I get a "duplicate file" conflict when creating a parent project with two library modules that use the same shared library libc++_shared.so .
( NOTE : Please do not consider this a “duplicate question.” I read several related posts that helped me get this far. However, none of the posts gave an answer that works in my case with NDK artifacts.)
The assembly worked correctly when I had only 1 such library module. Adding a second library module now creates a conflict.
Consider the following project structure: one parent project, 2 "child" projects, but each project is at the same directory level (i.e. not hierarchically nested)
ProjectA/ (Parent) LibraryModuleA1/ build/exploded-aar/com.package.name/ LibraryModuleB1/<version>/jni/armeabi-v7a/libc++_shared.so LibraryModuleC1/<version>/jni/armeabi-v7a/libc++_shared.so build.gradle (bgA1) Test_APK_Module A1T/ build.gradle (bgA1T) build.gradle (bgPA) ProjectB/ LibraryModuleB1/ (Uses NDK) build/lib/armeabi-v7a/libc++_shared.so build.gradle (bgB1) build.gradle (bgPB) ProjectC/ LibraryModuleC1/ (Uses NDK) build/lib/armeabi-v7a/libc++_shared.so build.gradle (bgC1) build.gradle (bgPC)
Library module A1 depends on both library modules B1 and C1.
A1 → B1
A1 → C1
Projects B and C have NDK-based code and build / verify correctly. Both depend on the shared libc++_shared.so .
However, when creating project A, I get the following error during the task :LibraryModuleA1:packageDebugTest :
Error: duplicate files during packaging of APK /ProjectA/LibraryModuleA1/build/apk/LibraryModuleA1-debug-test-unaligned.apk Path in archive: lib/armeabi-v7a/libc++_shared.so Origin 1: /ProjectA/LibraryModuleA1/build/exploded-aar/com.package.name/LibraryModuleB1/<version>/jni/armeabi-v7a/libc++_shared.so Origin 2: /ProjectA/LibraryModuleA1/build/exploded-aar/com.package.name/LibraryModuleC1/<version>/jni/armeabi-v7a/libc++_shared.so You can ignore those files in your build.gradle: android { packagingOptions { exclude 'lib/armeabi-v7a/libc++_shared.so' } } * What went wrong: Execution failed for task ':LibraryModuleA1:packageDebugTest'. > Duplicate files copied in APK lib/armeabi-v7a/libc++_shared.so File 1: /ProjectA/LibraryModuleA1/build/exploded-aar/com.package.name/LibraryModuleC1/<version>/jni/armeabi-v7a/libc++_shared.so File 2: /ProjectA/LibraryModuleA1/build/exploded-aar/com.package.name/LibraryModuleC1/<version>/jni/armeabi-v7a/libc++_shared.so :LibraryModuleA1:packageDebugTest FAILED
What have i tried so far
- I tried to add the proposed closure to my
build.gradle file, but to which build.gradle file do I add it? I added a bgA1 to bgA1 , bgB1 and bgC1 (one at a time), without any success. - The proposed closure uses
exclude 'lib/armeabi-v7a/libc++_shared.so' . Each "child" library module creates a libc++_shared.so along the build/lib path. However, I noticed that the parent library module copies the libc++_shared.so to jni/armeabi-v7a/libc++_shared.so inside the build/exploded-aar directory structure. (See above). Should I read exclude 'jni/armeabi-v7a/libc++_shared.so (i.e. jni vs lib ) instead of closing? - Since I'm using the Gradle plugin 0.9.1, I tried using
pickFirst instead of exclude , but that also failed.
Can someone help determine how I can configure the closure of `packagingOptions' for my current case?
Thank you for your help!
source share