Following various sets of instructions, it seems that I should add native libraries to app/src/main/jniLibs
and they'll be linked up automagically. However when I do this (for OpenCV) I get the following:
Error:duplicate files during packaging of APK /.../app/build/outputs/apk/app-debug-unaligned.apk
Path in archive: lib/armeabi/libopencv_java.so
Origin 1: /.../app/src/main/jniLibs/armeabi/libopencv_java.so
Origin 2: /.../build/intermediates/exploded-aar/AppName/.libraries/opencv/unspecified/jni/armeabi/libopencv_java.so
You can ignore those files in your build.gradle:
android {
packagingOptions {
exclude 'lib/armeabi/libopencv_java.so'
}
}
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK lib/armeabi/libopencv_java.so
File 1: /.../app/src/main/jniLibs/armeabi/libopencv_java.so
File 2: /.../app/src/main/jniLibs/armeabi/libopencv_java.so
Adding the exclude
section doesn't work. There's only one copy of the file, but somehow it's being referenced twice, and it seems the second (build
) include is something auto-generated. What can I do?
In case of duplicate libraries (*.so) files, exclude option will not help as we cannot completely exclude the native binaries. There is one more option in packagingOptions. It is 'pickFirst'. We can avoid duplicate files error and include the first one the compiler encounters.
packagingOptions {
pickFirst 'lib/armeabi/libopencv_java.so'
}
ndk-build
was generating duplicates of all of the packages from OpenCV. I removed all of the .so
libraries from my app, apart from my actual app library, and then it packaged up fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With