Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidStudio Gradle: how to configure buildTypes, and check for which buildType when building?

How can I check if a buildType is debuggable in my build.gradle?

I want to do something like:

if(debug) {
     file.write("xxxxx")
}

in my build.gradle

Also, how can I build a debug and release buildType from AndroidStudio? I don't mean from command line by typing ./gradlew assembleRelease or assembleDebug, I mean from the IDE itself when you press the play button. Is this possible?

I have buildTypes configured as such in my android block:

buildTypes {
    release {
        signingConfig signingConfigs.storeSign
        defaultConfig {
            versionCode 1100
            versionName "1.1.00"
        }
    }
    debug {
        defaultConfig {
            versionCode 1201
            versionName "1.2.01"
        }
    }
}
like image 494
Prem Avatar asked Feb 20 '14 15:02

Prem


1 Answers

How can I check if a buildType is debuggable in my build.gradle?

You can do so using the buildType's debuggable flag. The end result might look something like this:

android {

    buildTypes.all { buildType ->
        println buildType.name
        print "Debuggable: "
        println buildType.debuggable
    }
}

Also, how can I build a debug and release buildType from AndroidStudio?

Click the "Build Variants" button in the lower left corner of Android Studio to open up the Build Variants panel. From there you can select the build variant that you want to use when you run/debug.

enter image description here

like image 58
Bryan Herbst Avatar answered Nov 09 '22 17:11

Bryan Herbst