11

My react native app was running correctly, but suddenly I started getting error:

error 1: Execution failed for task ':react-native-webview:compileDebugKotlin'.

so for this in android/build.gradle I added kotlinVersion = "1.5.31" and also dependencies added classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31".

After this I got the following error:

* What went wrong:
Execution failed for task ':app:mergeDebugNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'lib/arm64-v8a/libfbjni.so'. If you are using jniLibs and CMake IMPORTED targets, see https://developer.android.com/studio/preview/features#automatic_packaging_of_prebuilt_dependencies_used_by_cmake

for this, inside android/app/build.gradle under android{...} I added:

packagingOptions {
    pickFirst 'lib/x86/libc++_shared.so'
    pickFirst 'lib/x86_64/libjsc.so'
    pickFirst 'lib/arm64-v8a/libjsc.so'
    pickFirst 'lib/arm64-v8a/libc++_shared.so'
    pickFirst 'lib/x86_64/libc++_shared.so'
    pickFirst 'lib/armeabi-v7a/libc++_shared.so'
    pickFirst 'lib/armeabi-v7a/libfbjni.so'
}

but even after this I am getting the same error again: More than one file was found with OS independent path 'lib/arm64-v8a/libfbjni.so'

pratteek shaurya
  • 850
  • 2
  • 12
  • 34
  • 1
    [Try this](https://github.com/facebook/react-native/issues/35210). It is a general problem – BK52 Nov 05 '22 at 12:20

7 Answers7

14

Add following lines inside the android>build.gradle file -

allprojects {
repositories {
    ...
    exclusiveContent {
       // We get React Native's Android binaries exclusively through npm,
       // from a local Maven repo inside node_modules/react-native/.
       // (The use of exclusiveContent prevents looking elsewhere like Maven Central
       // and potentially getting a wrong version.)
       filter {
           includeGroup "com.facebook.react"
       }
       forRepository {
           maven {
               url "$rootDir/../node_modules/react-native/android"
           }
       }
   }
}

This issue occurred from November 4th 2022. See the reference: https://github.com/facebook/react-native/issues/35210

Ali Hasan
  • 3,843
  • 1
  • 5
  • 9
9

You can add given code in app/build.gradle. I resolved my error by adding the following code.

android {
    defaultConfig {
    
    }
    
    packagingOptions {
        pickFirst '**/libjsc.so'
        pickFirst '**/libc++_shared.so'
        pickFirst '**/libfbjni.so'
        pickFirst '**/llibturbomodulejsijni.so'
        pickFirst '**/libturbomodulejsijni.so'
        // Add more according to your error here
    }
}

after adding pickFirst '**/libfbjni.so' i got two more errors so i have added pickFirst '**/llibturbomodulejsijni.so' and pickFirst '**/libturbomodulejsijni.so' to resolve my error.

If your app crashes on open then in android/build.gradle add this

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 {
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
}
Shivam
  • 2,147
  • 1
  • 11
  • 28
2

Try to add this code to your app build.gradle under allprojects -> repositories:

 exclusiveContent {
            filter {
                includeGroup "com.facebook.react"
            }
            forRepository {
                maven {
                    url "$rootDir/../node_modules/react-native/android"
                }
            }
        }

sync your code with gradle and run again.

1

My application was in version 0.68.2 and I updated to new version 0.68.5 and it worked. This issue is happening after 04/November/2022 found versions in this post GitHub

0

Based on @BK52 's mentioned github thread, I added this snippet into app/build.gradle

android {
    defaultConfig {
    // existing code
            packagingOptions {
            pickFirst '**/libc++_shared.so'
            pickFirst '**/libfbjni.so'
        }
    }
}

It worked for me and the error seems to disappear. I am using RN 0.68.2.

Anass
  • 301
  • 1
  • 3
  • 13
0

if your react native version is lower then 0.63 or 0.64.X try these steps

in android/app/build.gradle add these lines

android {

packagingOptions {
    pickFirst 'lib/x86/libc++_shared.so'
    pickFirst 'lib/x86_64/libc++_shared.so'
    pickFirst 'lib/armeabi-v7a/libc++_shared.so'
    pickFirst 'lib/arm64-v8a/libc++_shared.so'
    pickFirst 'lib/x86/libfbjni.so'
    pickFirst 'lib/x86_64/libfbjni.so'
    pickFirst 'lib/armeabi-v7a/libfbjni.so'
    pickFirst 'lib/arm64-v8a/libfbjni.so'       
}
//other code

}

and in android/build.gradle add these lines by changing your current native version inside the resolutionStrategy

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:0.64.2"  //<-- please change here 
        // please change the version here to your current react native version
    }
}
//other code
}

then cd android ./gradlew clean and run npx react-native run-android

0

Add this in the allprojects area of your android/buld.gradle file.

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
        }
    }
Manoj Alwis
  • 1,337
  • 11
  • 24