How to fix libgnustl_shared.so file that is duplicated in third-party sdks?

When I used gradle to build and run apk, I get the error below:

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 
+5
source share
3 answers

Finally, I transfer one of these files to assets and upload it manually before using

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

This does not work very well, although it fixes a DuplicateFileException error. If anyone gets a better way, tell me. Thanks! ^ _ ^

+2
source

I was able to fix this by adding the code below to build.gradle . It is a kind of hack; there should be a more elegant fix, for example, you do not need to include a version of React Native. Ideally, React Native will solve this. I discovered the problem: https://github.com/facebook/react-native/issues/9454

 import com.android.build.gradle.internal.pipeline.TransformTask def deleteDuplicateJniFiles() { def files = fileTree("${buildDir}/intermediates/exploded-aar/com.facebook.react/react-native/0.31.0/jni/") { include "**/libgnustl_shared.so" } files.each { it.delete() } } tasks.withType(TransformTask) { pkgTask -> pkgTask.doFirst { deleteDuplicateJniFiles() } } 
+2
source

The clean solution is to explicitly tell Gradle what you know about the problem and accept any of these files. Depending on the architecture you support, you may only need some of them. You can find the details in the documentation.

 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' } } 
+1
source

All Articles