如何修复在第三方sdks中复制的libgnustl_shared.so文件?

Wai*_*Tam 8 java-native-interface android duplicates android-library android-gradle-plugin

当我使用gradle构建并运行apk时,我得到以下错误::::

Error:Execution failed for task ':app:transformNative_libsWithMergeJniLibsForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK lib/armeabi-v7a/libgnustl_shared.so
    File1:  
app/build/intermediates/exploded-aar/com.facebook.react/react-native/0.20.1/jni
    File2:  
app/build/intermediates/exploded-aar/app/videosdk/unspecified/jni
Run Code Online (Sandbox Code Playgroud)

Gak*_*ket 6

更清洁的解决方案是明确告诉Gradle您知道该问题并接受任何这些文件.根据您支持的体系结构,您可能只需要一些.您可以在文档中找到详细信息

android {

 // some stuff
 packagingOptions {
        pickFirst 'lib/armeabi-v7a/libgnustl_shared.so'
        pickFirst 'lib/arm64-v8a/libgnustl_shared.so'
        pickFirst 'lib/x86_64/libgnustl_shared.so'
        pickFirst 'lib/x86/libgnustl_shared.so'
    }
}
Run Code Online (Sandbox Code Playgroud)


Wai*_*Tam 3

Finally\xef\xbc\x8ci move one of the so file to assets,and load it manually before used

\n\n
 String path = getApplication().getFilesDir().toString() + "/armeabi-v7a/libgnustl_shared.so";\n if (!FileUtils.isFileExit(path))  //move so from assets to another dir\n       FileUtils.initSOFileFromAssetsFile(getApplication()); \n System.load(path);\n
Run Code Online (Sandbox Code Playgroud)\n\n

This works not very well , although it fixes the DuplicateFileException bug .\nIf anyone get the better way pls tell me . \nThanks!^_^

\n

  • 您能更详细地解释一下吗?我不明白你的意思“我将其中一个 so 文件移动到资产”。 (2认同)