Gradle: execute code depending on the type of assembly (or variant)

I want to execute some code depending on the type of assembly (release, debug). in particular, I want to change the name of the APK depending on the type of assembly ... something like this,

if (buildType.name == 'release') {
  project.archiveBaseName = 'blah';
} else if (buildType.name == ...) {
  ...
}

I do not know where to place this code. I can iterate over assembly types,

android.buildTypes.each{ type ->
    print type.name
}

but this, of course, gives me all assembly types, not the current assembly type.

thanks.

+4
source share
1 answer

I believe buildTypes is the function you need: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Types

android {
    buildTypes {
        debug {
            packageNameSuffix ".debug"
        }
    }
}

Does it help?

0
source

All Articles