I want to make APK split based on CPU ABI according to http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits, however I want to split the APK only for a certain product flavor.
So my build.gradle
file has the following product flavors plain
and market
. Actually I want the APK split to be performed when building market
flavor.
android {
productFlavors {
plain {
}
market {
splits {
abi {
enable true
reset()
include 'armeabi', 'armeabi-v7a', 'x86', 'mips'
universalApk true
}
}
}
}
}
However, when I invoke gradle assemblePlainDebug
and assembleMarketDebug
, both of them produces the multiple APK. Is there something wrong with the configuration above?
I'm using com.android.tools.build:gradle:1.2.3
.
123 let's go Simply put, a product flavor is a variant of your app. It is very useful when you want to create multiple versions of your app. This means you can generate different versions or variants of your app using a single codebase.
Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.
There is no direct way to get the current flavor; the call getGradle(). getStartParameter().
I've been looking for a way to do this for a while and haven't found a solid solution. Something to do with the splits having to be run before resolving the buildTypes and productFlavors.
The Android Gradle - is use splits only for release possible? question had answer that I thought useful. It basically relies on a project property, passed in when building via the command line or continuous integration invironment, to set weather the split apk's option is enabled or not.
I used it like this:
splits {
abi {
enable project.hasProperty('splitApk')
reset()
include 'x86', 'armeabi-v7a', 'mips', 'armeabi'
universalApk true
}
}
and then depending on what falvour or build type you are building you can include:
./gradlew --project-prop splitApk assembleMarketDebug
This should then only enable the apk split when explicitly told too and should stay disabled for everything else.
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