Vai*_*ske 34 android build.gradle react-native
* 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/armeabi-v7a/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
Run Code Online (Sandbox Code Playgroud)
在 app/build.gradle 文件中
packagingOptions {
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
}
Run Code Online (Sandbox Code Playgroud)
仍然报错....
尝试过
In app/build.gradle file
packagingOptions {
pickFirst 'lib/x86/libfbjni.so'
pickFirst 'lib/x86_64/libfbjni.so'
pickFirst 'lib/arm64-v8a/libfbjni.so'
pickFirst 'lib/armeabi-v7a/libfbjni.so'
}
Run Code Online (Sandbox Code Playgroud)
但它给出以下错误
More than one file was found with OS independent path 'lib/armeabi-v7a/libc++_shared.so'.
Run Code Online (Sandbox Code Playgroud)
Ram*_*rog 75
==旧解决方案==
\n当前react-native的修复
\n我们建议所有 React Native 用户将此修复应用到您的顶级 build.gradle 文件,如下所示:
\n// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n // ...\n}\n\n\nallprojects {\n repositories {\n+ exclusiveContent {\n+ // We get React Native\'s Android binaries exclusively through npm,\n+ // from a local Maven repo inside node_modules/react-native/.\n+ // (The use of exclusiveContent prevents looking elsewhere like Maven Central\n+ // and potentially getting a wrong version.)\n+ filter {\n+ includeGroup "com.facebook.react"\n+ }\n+ forRepository {\n+ maven {\n+ // NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"\n+ url "$rootDir/../node_modules/react-native/android"\n+ }\n+ }\n+ }\n // ...\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n此修复将应用一个排他内容解析规则,该规则将强制 React Native Android 库的解析,以使用 node_modules 内的解析。
\n将应用程序更新到 React Native v0.71.0 后,将不再需要此修复。
\n==新解决方案==
\n我们已经为所有主要版本的react-native 准备了一个修补程序:
\n0.70.5: https: //github.com/facebook/react-native/releases/tag/v0.70.5
\n\xef\xb8\x8f 0.69.7:https://github.com/facebook/react-native/releases/tag/v0.69.7
\n0.68.5: https: //github.com/facebook/react-native/releases/tag/v0.68.5
\n\xef\xb8\x8f 0.67.5:https://github.com/facebook/react-native/releases/tag/v0.67.5
\n\xef\xb8\x8f 0.66.5:https://github.com/facebook/react-native/releases/tag/v0.66.5
\n\xef\xb8\x8f 0.65.3:https://github.com/facebook/react-native/releases/tag/v0.65.3
\n\xef\xb8\x8f 0.64.4:https://github.com/facebook/react-native/releases/tag/v0.64.4
\n\xef\xb8\x8f 0.63.5:https://github.com/facebook/react-native/releases/tag/v0.63.5
\n通过更新到这些补丁版本,您的 Android 版本应该可以重新开始工作。
\n为此,请在 package.json 中将react-native 的版本更改为相关的新补丁(例如,如果您使用的是 0.64.3,请更改为 0.64.4)并运行yarn install。不需要进行其他更改,但在尝试重新运行 Android 应用程序之前,您可能需要使用 cd android && ./gradlew clean 清理 Android 工件。
\n== 修复较旧的 React-native (< 0.63) ==
\n上述修复仅适用于 gradle 6.2 及更高版本。较旧的 React-Native 使用较旧的 gradle。
\n您可以通过查看 /android/gradle/wrapper/gradle-wrapper.properties 文件来确定您的 gradle 版本。
\n如果您使用的是使用 gradle 版本 6.1 或更低版本的旧版 React-native(例如 0.63 或更早版本),则必须使用不同的解决方法,因为 gradle 6.1 不支持 ExclusiveContent。
\n将其添加到 android/buld.gradle 文件的 allprojects 区域中。
\ndef 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())\n\nallprojects {\n configurations.all {\n resolutionStrategy {\n // Remove this override in 0.65+, as a proper fix is included in react-native itself.\n force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n该修补程序必须强制使用 React Native 的版本,而不是使用 ExclusiveContent。推荐的修补程序 shells 到节点来读取当前版本的react-native。如果您硬编码了react-native的版本,那么当您将来升级项目时,如果您忘记删除此修补程序,您的构建将会失败。
\n请注意,此修复很脆弱,因为如果您位于 monorepo 中,package.json 的位置可能会有所不同,并且如果您使用 nvm 等节点包管理器,则节点可能不可用。
\n\n\n\n
Jim*_*mes 11
在 allProjects-build.gradle-repositories 下添加以下代码。它适用于我一直在从事的一个旧项目。
exclusiveContent {
filter {
includeGroup "com.facebook.react"
}
forRepository {
maven {
// NOTE: if you are in a monorepo, you may have "$rootDir/../../../node_modules/react-native/android"
url "$rootDir/../node_modules/react-native/android"
}
}
}
Run Code Online (Sandbox Code Playgroud)
转到 android{} 内的 yourProject/app/build.gradle
如果您仔细查看错误消息,您会发现该库不在pickFirst列表中。即lib/armeabi-v7a/libc++_shared
但请记住,您必须在 pickFirst 列表中包含所有 React 架构选项。 即armeabi-v7a、arm64-v8a、x86、x86_64。
做这个:
android {
packagingOptions {
pickFirst 'lib/armeabi-v7a/libc++_shared.so'
pickFirst 'lib/arm64-v8a/libc++_shared.so'
pickFirst 'lib/x86/libc++_shared.so'
pickFirst 'lib/x86_64/libc++_shared.so'
}
}
Run Code Online (Sandbox Code Playgroud)
或者你可以这样做:如果你不知道图书馆的名称,这也很好
android {
packagingOptions {
pickFirst '**/*.so'
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
29105 次 |
| 最近记录: |