React Native ./gradlew assembleRelease assembleAndroidTest 失败:"More than one file found with OS independent path"

React Native ./gradlew assembleRelease assembleAndroidTest fails: "More than one file found with OS independent path"

我是 运行 gradle 命令:./gradlew assembleRelease assembleAndroidTest 它失败并出现以下错误:

> Task :react-native-ffmpeg:mergeDebugAndroidTestNativeLibs FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-ffmpeg:mergeDebugAndroidTestNativeLibs'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > More than one file was found with OS independent path 'lib/x86/libc++_shared.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

我按照说明 here 并将此代码添加到我的 build.gradle:

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

不过,这些packagingOptions好像没什么区别。我应该注意到 运行 只是 assembleRelease 有效,只有当我添加 assembleAndroidTest 时才会出现问题。我在 react-native-ffmpeg github 上打开了一个 issue,但这似乎是一个更普遍的 gradle/android 问题,这就是我在这里发帖的原因。

如果您将 app: 添加到 gradle 任务之前,错误就会消失。这是对我有用的构建命令:./gradlew app:assembleRelease app:assembleAndroidTest.