c++ - How to Exclude Duplicate C Shared Libraries (.so) in a Multi-Project Android Build? -
i "duplicate files" conflict when building parent project 2 library modules, create utilize of same libc++_shared.so
shared library.
(note: please not consider "duplicate question". have read several related posts, have helped me far. however, no posts have provided reply works in case involving ndk artifacts.)
the build working correctly when had 1 such library module. add-on of sec library module creating conflict.
consider next project structure: 1 parent project, 2 "child" projects - each project located @ same directory level (i.e. not nested hierarchically)
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 & c1. a1 -> b1 a1 -> c1
projects b , c both have ndk-based code , build/test correctly. both depend on libc++_shared.so
shared library.
however, when building project a, next error during :librarymodulea1:packagedebugtest
task:
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 can ignore files in build.gradle: android { packagingoptions { exclude 'lib/armeabi-v7a/libc++_shared.so' } } * went wrong: execution failed 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 i've tried far
i attempted add together suggested closurebuild.gradle
file, build.gradle
file add together to? have added closure bga1
, bgb1
, , bgc1
(one @ time), no success. the suggested closure says utilize exclude 'lib/armeabi-v7a/libc++_shared.so'
. each "child" library module builds libc++_shared.so
file under build/lib
path. however, noticed parent library module copies libc++_shared.so
file under jni/armeabi-v7a/libc++_shared.so
within build/exploded-aar
directory structure. (see above) should closure instead read exclude 'jni/armeabi-v7a/libc++_shared.so
(i.e. jni
vs. lib
)? since using gradle plugin 0.9.1, tried using pickfirst
in place of exclude
, wasn't successful either. can help determine how should configure `packagingoptions' closure given case?
thank help!
i ran same problem , had no luck exclude or pickfirst. used ugly workaround. thought create 'native-libs' folder in build directory of main project, re-create required *.so files ndk library projects there , tell build scheme bundle libs in apk.
in main project (the app project), explicitely define list of modules contain ndk codes on depend
// ndk stuff. have explicitely manage our ndk dependencies ext.jniprojects = [project(':ndklib1'), project(':ndklib2'), project(':ndklib3')] apply from: '../depend_ndk.gradle'
and then, 'depend_ndk.gradle' gradle external script contains
// build helper projects depends on native library ndk part // define list of ndk library depend on in project main file : // ext.jniprojects = [project(':ndklib1')] // apply : 'depend_ndk.gradle' buildscript { repositories { jcenter() mavencentral() } dependencies { classpath 'com.android.tools.build:gradle:0.12.+' } } import com.android.build.gradle.tasks.packageapplication // workaround, create new 'native-libs' folder in current project , // re-create .so depend on def ndklibsdir = new file(builddir, 'native-libs') ndklibsdir.mkdir() task copydependingnativelibs(type: copy) { // doc re-create http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.copy.html println 'jniprojects ' + jniprojects jniprojects.each { from(new file(it.builddir, 'native-libs')) { include '**/*.so' } } ndklibsdir } tasks.withtype(packageapplication) { pkgtask -> pkgtask.jnifolders = new hashset<file>() pkgtask.jnifolders.add(ndklibsdir) pkgtask.dependson copydependingnativelibs }
android c++ android-ndk android-gradle
No comments:
Post a Comment