When does ADT set BuildConfig.DEBUG to false?

Currently you can get the correct behavior by disabling "Build Automatically", cleaning the project and then export via "Android Tools -> Export Signed Application Package". When you run the application BuildConfig.DEBUG should be false.


With Eclipse, I always disable "Build Automatically" option before Exporting the app in release. Then I clean the project and export. Otherwise it starts compiling in debug mode, and then the value of BuildConfig.DEBUG may be wrong.

With Android Studio, I simply add my own custom variable in the build.gradle:

buildTypes {
    debug {
        buildConfigField "Boolean", "DEBUG_MODE", "true"
    }
    release {
        buildConfigField "Boolean", "DEBUG_MODE", "false"
    }
}

When I build the project, the BuildConfig.java is generated as follows:

public final class BuildConfig {
  // Fields from build type: debug
  public static final Boolean DEBUG_MODE = true;
}

Then in my code I can use:

if (BuildConfig.DEBUG_MODE) {
    // do something
}

I recommand to clean after switching debug/release build.


It doesn't work properly:

Issue 27940: BuildConfig.DEBUG is "true" for exported application package

It's disappointing that they sometimes release buggy features.