skip to Main Content

My react native project build fails somehow because of this error:

Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.MergeNativeLibsTask$MergeNativeLibsTaskWorkAction
   > 2 files found with path 'lib/arm64-v8a/libfbjni.so' from inputs:
      - C:UsersAntonio.gradlecachestransforms-37cca348744e25f57fc2d9f871aa73c9atransformedjetified-react-native-0.71.0-rc.0-debugjniarm64-v8alibfbjni.so
      - C:UsersAntonio.gradlecachestransforms-38b0f5c7017bf081f79b63ea5b053dc0transformedjetified-fbjni-0.3.0jniarm64-v8alibfbjni.so
     If you are using jniLibs and CMake IMPORTED targets, see
     https://developer.android.com/r/tools/jniLibs-vs-imported-targets

Anybody got a clue what could cause the build to fail? I haven’t edited any build file and/or removed/installed/upgraded new packages thanks

8

Answers


  1. For me this worked (after reading Tony’s link), my version of react was 0.66.0
    Changed this file androidappbuild.gradle

    implementation "com.facebook.react:react-native:+"  // From node_modules
    

    to

    implementation "com.facebook.react:react-native:0.66.0!!"  // From node_modules
    
    Login or Signup to reply.
  2. Here’s a workaround to fix this problem if you are not using latest version of react-native.
    https://github.com/facebook/react-native/issues/35210

    Login or Signup to reply.
  3. Go to android folder -> build.gradle file -> inside allprojects object and add following code. Add react native version from node_modules -> react-native -> package.json // "version": "0.68.2".

    configurations.all {
        resolutionStrategy {
            force 'com.facebook.react:react-native:0.68.2'
        }
    }
    

    See fb/rn#35204

    Login or Signup to reply.
  4. work for me, if your react native application version >= 0.63 you can update the patch version which should fix your problem.

    link: https://github.com/facebook/react-native/issues/35210#:~:text=We%20have%20prepared%20releases%20for%20all%20the%20main%20versions%20of%20react%2Dnative%20with%20an%20hotfix%3A

    if not just go to android/build.gradle and then in the allprojects object add the following code with the current version of react native in package.json

    configurations.all {
     resolutionStrategy {
      force 'com.facebook.react:react-native:CURRENT_VERSION_OF_REACT_NATIVE'
     }
    }
    
    Login or Signup to reply.
  5. I had the same issue. There is a new patch for react-native now so update it in your package.json.

    Mine is

    "react-native": "^0.70.3"
    

    and I changed it to

    "react-native": "^0.70.5"
    

    which worked for me

    Login or Signup to reply.
  6. The answer lies here depending on the version of your react native. Patches are available for RN version 0.63 and up

    https://github.com/facebook/react-native/issues/35210

    Tips:

    • Don’t just update react-native package, do an npm install
    • Clean gradle before running the app
    • Only add the code below IF your react native version is < 0.63
    def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())
    
    allprojects {
        configurations.all {
            resolutionStrategy {
                // Remove this override in 0.65+, as a proper fix is included in react-native itself.
                force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
            }
        }
    }
    
    Login or Signup to reply.
  7. Short answer:

    in your android/app/build.gradle

    change

    implementation 'com.facebook.react:react-native:+'

    to —> (replace 0.67.2 with your current react native version)

    implementation 'com.facebook.react:react-native:0.67.2!!'

    Long answer:

    This is happening because all the templates reference the React Native dependency by range, like implementation 'com.facebook.react:react-native:+'. Usually this dependency gets resolved from the local Maven repo in ./node_modules/react-native/android but since it has been published to Maven Central it’s now grabbing the very latest RC.

    You can resolve this problem by forcing the React Native dependency to the version you expect with something like this implementation 'com.facebook.react:react-native:0.67.2!!' in your app’s Gradle file. The !! is shorthand for restricting Gradle from upgrading if your project or its transitive dependencies depend on a newer version.

    Login or Signup to reply.
  8. This is the Official recommended fix!

    Found through this issue: https://github.com/facebook/react-native/issues/35210.

    Copied from this PR here

    For my RN 0.66.0 project I only had to add theses lines:

    allprojects {
        repositories {
            exclusiveContent {
                // Official recommended fix for Android build problem with React Native versions below 0.71
                // https://github.com/facebook/react-native/issues/35210
                // TODO: remove this exclusiveContent section when we upgrade to React Native 0.71 (or above)
                // copied from https://github.com/Scottish-Tech-Army/Volunteer-app/pull/101/commits/40a30310ee46194efbaf1c07aef8a0df70231eeb
                filter {
                    includeGroup "com.facebook.react"
                }
                forRepository {
                    maven {
                        url "$rootDir/../node_modules/react-native/android"
                    }
                }
            }
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search