Jeffrey Blattman
Jeffrey Blattman

Reputation: 22637

gradle: execute code depending on the build type (or variant)

I want to execute some code depending on the build type (release, debug). specifically, i want to change the APK name depending on the build type ... something like this,

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

I don't know where to put this code however. I can iterate over the build types,

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

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

Upvotes: 4

Views: 1469

Answers (1)

Jean Lestang
Jean Lestang

Reputation: 861

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

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

Does it help?

Upvotes: 1

Related Questions