react-native-webview: error: package androidx.core.content does not existimport androidx.core.content.FileProvider;
Bug description:
New React Native Project. “react-native-webview”: “6.0.1”
Error when build (react-native run-android)
Task :react-native-webview:compileDebugJavaWithJavac (omited)\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewFileProvider.java:3: error: package androidx.core.content does not exist import androidx.core.content.FileProvider;
To Reproduce:
- New React Native Project With Cli
- yarn add react-native-webview
- react-native link react-native-webview
App.json
import React, {Component} from 'react'
import {StyleSheet} from 'react-native'
import { WebView } from 'react-native-webview'
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<WebView source={{uri: 'https://www.google.com'}} />
);
}
}
Complete Error:
info Starting JS server… info Building and installing the app on the device (cd android && gradlew.bat app:installDebug)…
Configure project :react-native-webview :react-native-webview:reactNativeAndroidRoot C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native\android
Task :react-native-webview:compileDebugJavaWithJavac C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewFileProvider.java:3: error: package androidx.core.content does not exist import androidx.core.content.FileProvider; ^ C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewFileProvider.java:10: error: cannot find symbol public class RNCWebViewFileProvider extends FileProvider { ^ symbol: class FileProvider C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewModule.java:14: error: cannot find symbol import androidx.annotation.RequiresApi; ^ symbol: class RequiresApi location: package androidx.annotation C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewModule.java:15: error: package androidx.core.content does not exist import androidx.core.content.ContextCompat; ^ C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewModule.java:16: error: package androidx.core.content does not exist import androidx.core.content.FileProvider; ^ C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewModule.java:178: error: cannot find symbol @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) ^ symbol: class RequiresApi location: class RNCWebViewModule C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewModule.java:224: error: cannot find symbol if (ContextCompat.checkSelfPermission(getCurrentActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ^ symbol: variable ContextCompat location: class RNCWebViewModule C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewModule.java:352: error: cannot find symbol return FileProvider.getUriForFile(getReactApplicationContext(), packageName + “.fileprovider”, capturedFile); ^ symbol: variable FileProvider location: class RNCWebViewModule Note: C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewManager.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: C:\GIT\Ragnarok\ragnarok-app-webview\node_modules\react-native-webview\android\src\main\java\com\reactnativecommunity\webview\RNCWebViewManager.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. 8 errors
Task :react-native-webview:compileDebugJavaWithJavac FAILED
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ‘:react-native-webview:compileDebugJavaWithJavac’.
Compilation failed; see the compiler error output for details.
Environment:
- OS: Windows
- OS version: 10
- react-native version: 0.59.8
- react-native-webview version: 6.0.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 34
- Comments: 22 (1 by maintainers)
Commits related to this issue
- chore(release): 6.0.2 [skip ci] ## [6.0.2](https://github.com/react-native-community/react-native-webview/compare/v6.0.1...v6.0.2) (2019-05-19) ### Bug Fixes * **AndroidX support:** Fixed broken im... — committed to react-native-webview/react-native-webview by semantic-release-bot 5 years ago
- fix(AndroidX support): Fixed broken import + added instructions (#583) Hello, in order to use react-native-webview > 6.0.2 please make your android/gradle.properties contains: ``` android.useAndroi... — committed to phuongwd/react-native-webview by Titozzz 5 years ago
- chore(release): 6.0.2 [skip ci] ## [6.0.2](https://github.com/react-native-community/react-native-webview/compare/v6.0.1...v6.0.2) (2019-05-19) ### Bug Fixes * **AndroidX support:** Fixed broken im... — committed to phuongwd/react-native-webview by semantic-release-bot 5 years ago
- chore(release): 6.0.2 [skip ci] ## [6.0.2](https://github.com/react-native-community/react-native-webview/compare/v6.0.1...v6.0.2) (2019-05-19) ### Bug Fixes * **AndroidX support:** Fixed broken im... — committed to noproblem23/react-native-webview by noproblem23 5 years ago
- chore(release): 1.0.0 [skip ci] # 1.0.0 (2023-09-13) ### Bug Fixes * **android:** add null reference check for onMessage on android ([#770](https://github.com/CodinDotTop/react-native-webview/issue... — committed to CodinDotTop/react-native-webview by semantic-release-bot 10 months ago
it’s weird, try to remove it first with
react-native uninstall react-native-webview, then install it again withreact-native install react-native-webview@5.8.1maybe your local still caching the last installedadd jetifier will fixed it npm install --save-dev jetifier npx jetify npx react-native run-android
I currently have the same problem, but I was able to find that you can add
to make your project compatible with AndroidX. However, I still get
This is very frustrating as even the fresh install of the app from scratch wouldn’t work…
thanks to @muhamad-rizki,
5.8.0works for me after several attempts.remember to
react-native unlink react-native-webview, install5.8.0version, andreact-native link react-native-webviewagain.I even used command
watchman watch-del-all && rm package-lock.json && rm -rf node_modules && rm -rf $TMPDIR/metro-* && rm -rf $TMPDIR/haste-map-* && npm installto nuke anything cached.were I to tell my native app dev peers that I spent one hour just to get the bloody system web view to work, they would roll on the floor laughing
this is typical working with React Native: most of the time you’re flying, but what we say to platform native component bridging? NOT TODAY
i was running getting this issue when installing without specifying the package version today. when i setted it to:
FYI – the relevant change is to add this to your
./android/gradle.propertiesfile:So frustrating ! I did a poc last week with version 5.8.1 and it worked fine, starting the new project today from scratch with new version not working anymore…
"react-native-webview": "^5.11.0",still getting the error. Now I’m going test with5.9.1.… and yes, I have add
[UPDATE]
5.9.1still giving the errortry v5.8.0 or 5.8.1
#520 try using rn webview lower than v6.0.0 like v5.9.0
I’m using below version to make it work: RN v59.8 RN Webview v5.8.0
@Titozzz just upgraded to 6.0.2, did clean up node_modules, still can’t get Android project to compile:
Enabled AndroidX following this guide
error mentioned in step 1 is gone, but
react-native-gesture-handleris failing because of using the support library v4, someone reported the issue theresince
react-native-gesture-handleris being widely used (partially becausereact-navigationrequires it), we might need to stay on 5.9.1 for a whilewith total fresh project, I did try react-native uninstall react-native-webview react-native install react-native-webview@5.8.1 or 5.8.0 still not work, waiting for later lib fix or other solution.
same behaviour not working 😦
@chrischenyc There is going to be a transition period from old libraries to AndroidX, I also use RNGH in my personal project. I keep publishing on the 5.X branch, I’ll add the incompatibilities to readme and discuss with other libraries maintainers.
I did as said and build was successful but this error pops up on the emulator.
Update:
Turns out In
MainApplication.javanew RNCWebViewPackage()was duplicated automatically