Reputation: 341
I have an Android app that I have been able to successfully build with Gradle (using Gradle 0.7). Now I want to set up Gradle to build two separate .APKs, one which had only ARM native libraries and the other with only Intel x86 native libraries. I have tried using productFlavors as in the following example:
How to configure NDK with Android Gradle plugin 0.7
However, with productFlavors specified in my Gradle script, the .APKs don't include any libraries at all (the libs dir itself is not in the .APK). Without productFlavors, the libraries are included - although the resulting APK will contain both ARM and x86 libraries.
With Gradle, it seems that our libraries are being placed in the following directories:
build/javaResources/release/lib/armeabi-v7a
build/javaResources/release/lib/x86
build/javaResources/debug/lib/armeabi-v7a
build/javaResources/debug/lib/x86
Without productFlavors in the Gradle script, Gradle seems to know to look in those directories for the libraries. So I'm at a loss as to what's going on. Why would the inclusion of productFlavors prevent Gradle from looking there for the libraries?
Upvotes: 3
Views: 5407
Reputation: 14463
About the example you are referring to, are you using the snippet from the main post or from its best answer ? The one in the main post is a bit outdated, maybe that's why it's not working with your project.
You have to use the abiFilter
property inside your productFlavors, and put your native libraries inside jniLibs
folder. Here is a sample build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion "20"
defaultConfig{
minSdkVersion 15
targetSdkVersion 20
versionCode 101
versionName "1.0.1"
}
flavorDimensions "abi"
productFlavors {
x86 {
flavorDimension "abi"
ndk {
abiFilter "x86"
}
versionCode 5
}
arm {
flavorDimension "abi"
ndk {
abiFilter "armeabi-v7a"
}
versionCode 2
}
all {
flavorDimension "abi"
versionCode 0
}
}
// make per-variant version code
applicationVariants.all { variant ->
// get the version code of each flavor
def abiVersion = variant.productFlavors.get(0).versionCode
// set the composite code
variant.mergedFlavor.versionCode = abiVersion * 100000 + defaultConfig.versionCode
}
}
note that in this example, I also modify the versionCode of the app for each productFlavor, so it properly works with the multiple APKs handling functionality on the Play Store.
You can get more background information on how all this is working here: http://ph0b.com/android-studio-gradle-and-ndk-integration/
Upvotes: 4