react-native-webview: constructor FileProvider in class FileProvider cannot be applied to given types

Repository here

Versions

react-native: 0.71.8

react-native-webview: 12.2.0

Steps are:

npx react-native@latest init reactnativewebviewissue

npm run android // All is fine

npm install --save react-native-webview

npm run android // Fault

Error message:

> Task :react-native-webview:compileDebugJavaWithJavac FAILED
37 actionable tasks: 24 executed, 13 up-to-date
/Volumes/Data/Workspace/github/reactnativewebviewissue/node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewFileProvider.java:13: error: constructor FileProvider in class FileProvider cannot be applied to given types;
    super(R.xml.file_provider_paths);
    ^
  required: no arguments
  found: int
  reason: actual and formal argument lists differ in length

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 19
  • Comments: 31 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I have the same issue. Downgrading to 11.26.1 seems to fix it.

no need to go all the way down to 11.x, "react-native-webview": "12.1.0" works fine (notice that there’s no ^, ~ before version)

On 12.1.0 the RNCWebViewFileProvider is intentionally left blank, on 12.2.0 is not.

I’m looking into making the usage of the new construction conditional on the availability of the new version of android modules … Please hold on.

The issue seems to be that 12.2.0 uses a FileProvider constructor (added in https://cs.android.com/androidx/platform/frameworks/support/+/a4385569db989747caf6b110b345a09ceb86acc7) that is not is not available in older androidx.core:core versions. This is the change - https://github.com/react-native-webview/react-native-webview/compare/v12.1.0...v12.2.0#diff-8ee52ba9097d8e8909a30c82091de2efd9d4cddc90953b1f320d8a3e8552775cR13. In my case it looks like the project was using androidx.core:core:1.7.0. I forced it to use latest version 1.10.1 by adding this in android/build.gradle and the build issue with react-native-webview 12.2.0 is solved:

allprojects {
  repositories {
    //...
    // Add this:
    configurations.all {
      resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'androidx.core' && requested.name == 'core') {
          details.useVersion '1.10.1'
        }
      }
    }
  }
}

I have the same issue. Downgrading to 11.26.1 seems to fix it.

Hi there, Solution above is working but not really safe. Forcing AndroidX Core to 1.10.1 can cause errors on other dependencies during build. Downgrade to 12.1.0 version is the best solution until the problem is solved or instruction is given.

Use the tilde on your dependency version range to avoid getting next minor version like "react-native-webview": "~12.1.0"

I have the same issue in my react-native application.

Fixed by installing 12.1.0

@willTerner it’s 12.1.0 not 12.2.1

I don’t want to change build.gradle files because in the future, when you have to update react-native, there will be problems with editing these files. I think it would be more correct to roll back to version 12.1.0 for now and wait for a fix from the developer

getting the same issue.


"react": "18.2.0",
"react-native": "0.71.8",
"react-native-webview": "^12.2.0"

Hello everyone … This is caused by https://github.com/react-native-webview/react-native-webview/commit/75e7801a6255b37f6887d29d10b9ba688e051416 which I merged a couple of days ago to mitigate large number of crashes reported in some OEM devices.

The motivation behind the fix was to leverage the change https://android-review.googlesource.com/c/platform/frameworks/support/+/1978527 which added a workaround to the androidx.core module to avoid stripping the File provider metadata.

The fix to androidx.core is available from https://developer.android.com/jetpack/androidx/releases/core#core-1.8.0-alpha06 (which was released more than an year ago) onwards. Could you folks upgrade to this version to avoid the crash ? Transitive dependency can be explicitly resolved as @mlazari suggested above https://github.com/react-native-webview/react-native-webview/issues/2978#issuecomment-1573469986

Thanks !

I have the same issue

@mganandraj I’ll revert while we find a solution to fix most people issues, keeping this open for follow up

Hi @Titozzz Sure, please go ahead with the revert.

I will continue investigating on getting this change back in a way that works with all versions of androidx libraries. We should also try to get react native to transitive depend on newer androidx versions.

For short term, I can add a local patch.

(By the way, Sorry for introducing this situation. I didn’t realize that so many codebases are still referring to the old version of androidx.core library.)

@mganandraj I’ll revert while we find a solution to fix most people issues, keeping this open for follow up

Hi, you just need to change the version of react-native-webview version to 12.1.0 like so

npm uninstall react-native-webview
npm install react-native-webview@12.1.0

After u can do a npx pod-install or cd ios && pod install that’s all.

add this in Build.gradle file

allprojects {
  repositories {
    //...
    // Add this:
    configurations.all {
      resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'androidx.core' && requested.name == 'core') {
          details.useVersion '1.10.1'
        }
      }
    }
  }
}

in app/build.gradle file add this in dependencies

def core_version = "1.10.1"
 implementation "androidx.core:core:$core_version"

Yes, there are 2 possible fixes that I know:

  1. Downgrade react-native-webview to 12.1.0
  2. Upgrade androidx.core:core as I shown in my previous message.

I have the same issue with

"react": "18.2.0",
"react-native": "0.71.8",
"react-native-webview": "^12.2.0"

Error Message

Task :react-native-webview:compileDebugJavaWithJavac FAILED
node_modules/react-native-webview/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewFileProvider.java:13: error: constructor FileProvider in class FileProvider cannot be applied to given types;
  super(R.xml.file_provider_paths);
  ^
required: no arguments
found: int
reason: actual and formal argument lists differ in length