React Native 错误:执行任务“:app:mergeDebugNativeLibs”失败

h6my8fg2  于 2022-11-17  发布在  React
关注(0)|答案(7)|浏览(340)

我的react原生应用程序运行正常,但突然开始出现错误:
错误1:Execution failed for task ':react-native-webview:compileDebugKotlin'.
因此,在android/build.gradle中,我添加了kotlinVersion = "1.5.31",并添加了依赖项classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31"
在此之后,我得到了以下错误:

* 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

对于这一点,在android下的android/app/build.gradle中{...}我添加了:

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'
}

但即使在这之后,我还是再次得到同样的错误:More than one file was found with OS independent path 'lib/arm64-v8a/libfbjni.so'

d8tt03nd

d8tt03nd1#

您可以在app/build.gradle中添加给定的代码。我通过添加以下代码解决了我的错误。

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
    }
}

添加pickFirst '**/libfbjni.so'后,我又得到了两个错误,所以我添加了pickFirst '**/llibturbomodulejsijni.so'pickFirst '**/libturbomodulejsijni.so'来解决我的错误。
如果您的应用程序在打开时崩溃,则在android/build.gradle中添加以下内容

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
        }
    }
}
ql3eal8s

ql3eal8s2#

android〉build.gradle 文件中添加以下行-

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"
           }
       }
   }
}

此问题发生于2022年11月4日。请参见参考:https://github.com/facebook/react-native/issues/35210

8yoxcaq7

8yoxcaq73#

尝试将此代码添加到您的app build.gradle中的所有项目-〉存储库下:

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

将您的代码与gradle同步并再次运行。

exdqitrt

exdqitrt4#

我的应用程序是在版本0.68.2和我更新到新版本0.68.5和它的工作。这个问题是发生在04/十一月/2022后发现版本在此职位GitHub

uxh89sit

uxh89sit5#

基于@BK52提到的github线程,我将此代码段添加到app/build.gradle

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

它对我起作用了,错误似乎消失了。我正在使用RN 0. 68. 2。

1cosmwyk

1cosmwyk6#

如果您的React本地版本低于0.63或0.64.X,请尝试以下步骤
在***android/app/build.gradle中***添加以下行

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

}

并在*android/build.gradle中*通过在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
}

然后cd android ./gradlew清理并运行npx react-native run-android

k3bvogb1

k3bvogb17#

将其添加到android/buld.gradle文件的allprojects区域。

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
        }
    }

相关问题