I have been developing for a while a library (in aar format) that is compatible with x86, armeabi-v7a and arm64-v8a abis. The library works as expected but, in order to reduce the final size, we want to develop two different libraries: one with arm64-v8a abi and one without it. The library depends on openCV (used in C++ language) and we have the following project structure:
src
|_ main
|_ jniLibs
| | arm64-v8a
|----| armeabi-v7a
| x86
Each abi folder contains libopencv_java3.so.
I have created two product flavours, each one with the abiFilters needed to work properly.
flavorDimensions "default"
productFlavors {
v7a {
externalNativeBuild {
cmake {
abiFilters 'x86', 'armeabi-v7a'
}
}
}
v8a {
externalNativeBuild {
cmake {
abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
}
}
}
}
Now I have two build variants to select and both compile without errors. However, the v7a aar still contains the arm64-v8a folder and library inside it. To solve this, I have added to v7a flavour the following:
packagingOptions {
exclude 'lib/arm64-v8a/libopencv_java3.so'
}
Now, v7a aar does not contain the arm64-v8a folder inside it but when I select v8a flavour, the folder exists but no libopencv_java3.so is placed inside it!
Should not this option only affect to v7a? What am I doing wrong? Any help will be appreciated.
Notes: gradle version tested: 3.1.2 and 3.1.4.
Till Gradle introduced ProductFlavours we were only able to build application with the a single configuration or default configuration. Since the introduction of ProductFlavours, we are able to create variables based on build types.
A flexible build system like Gradle and its Android specific plugin allows us to configure builds for different versions of the application. Versions of app could be based on deployment environments (dev, qa, prod) or products (free, paid) or device (phone, tv, wear) on which app is running on.
Other installation failures If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.
If not, here are some things you might see instead. If you get "command not found: gradle", you need to ensure that Gradle is properly added to your PATH. If you get something like: ERROR: JAVA_HOME is set to an invalid directory Please set the JAVA_HOME variable in your environment to match the location of your Java installation.
try to split differently, instead of using product favors -
alike this one can load armeabi-v7a
assembly on arm64-v8a
:
splits {
abi {
enable true
reset()
include "armeabi", "x86"
universalApk true
}
}
this would expect the (32bit version of the) library at armeabi/libopencv_java3.so
.
externalNativeBuild
only considers the libraries, which are being built (aka "your code"). if you insist on using the packagingOptions
, you should not define them globally, but per product flavor.
v7a {
...
packagingOptions {
exclude 'lib/arm64-v8a/libopencv_java3.so'
}
}
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