Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Gradle - is use splits only for release possible?

I want use "splits" by "abi", but only for release build. Is this possible? I try use ext variable and variable by "def" also which is set to false by default. This variable is set to true in buildTypes for releaseWithLog (and release).

But I don't know how Gradle work, because when I add writeln() with test message to "debug", "releaseWithLog" and "release" and run build, all messages are in output, so this confirms me that variable "splitsEnabled" is set to true though I build for debug - and I expect value "false" for debug (and not using splits for debug therefore).

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'
    ext {
        splitsEnabled = false
    }
    defaultConfig {
    ...
    }
    buildTypes {
        debug {
            ...
        }
        releaseWithLog {
            ...
            splitsEnabled = true
        }
        release.initWith(releaseWithLog)
        release {
            ...
        }
    }
    ...
    splits {
        abi {
            println(splitsEnabled)
            enable splitsEnabled
            reset()
            include 'x86', 'armeabi-v7a', 'armeabi'
            exclude 'x86_64', 'mips64', 'arm64-v8a', 'mips'
            universalApk true
        }
    }
    ... 
like image 615
Petr Daňa Avatar asked Jan 15 '15 13:01

Petr Daňa


People also ask

Which of the following is true about Gradle?

This is Expert Verified AnswerGradle is an open source, progressive general purpose build management system. It is configured on ANT, Maven, and lvy repositories. It supports Groovy based Domain Specific Language (DSL) over XML.

How many build Gradle file is there in one Android project?

gradle files in an Android Studio project?

How much time will Gradle sync take?

One bit of a downside is that it takes roughly 3 minutes to re-sync when we "Import Gradle Project".

What is BuildConfig in Android?

BuildConfig is a class containing static constants that is included in every Android application. BuildConfig includes some default fields such as DEBUG and FLAVOR but you can also add custom values via build. gradle .


1 Answers

You can solve this easily with a command line argument to Gradle, or the "Script parameters:" field for a Gradle task in Android Studio. I used -P to define 'dbgBld' symbol and used it for debug builds, e.g.:

gradle -PdbgBld installDebug

My build.gradle file has the following splits command:

splits {
    abi {
        enable !project.hasProperty('dbgBld')
        reset()
        include 'armeabi', 'armeabi-v7a', 'x86', 'mips'
        universalApk true
    }
}

Now to build release I use:

gradle assembleRelease

The 'dbgBld' symbol is not defined, so the splits enable field resolves to true and I get 5 APK files. When building for debugging, the -PdbgBld is already saved in my Android Studio configuration and I get only one "fat" APK for debugging, which results in much faster debug builds.

Greg

like image 172
gregko Avatar answered Sep 28 '22 08:09

gregko