Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android product flavors are not considered when using CPU ABI split in build.gradle

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.

like image 666
Randy Sugianto 'Yuku' Avatar asked Jul 02 '15 09:07

Randy Sugianto 'Yuku'


People also ask

When would you use a product flavors in your build setup?

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.

What are buildTypes and product Flavours in gradle?

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.

How do I get the current flavor in gradle?

There is no direct way to get the current flavor; the call getGradle(). getStartParameter().


1 Answers

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.

like image 178
speedynomads Avatar answered Oct 06 '22 00:10

speedynomads