Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does ADT set BuildConfig.DEBUG to false?

People also ask

What is BuildConfig DEBUG?

In recent versions of the Android Developer Tools (ADT) for Eclipse, there's a class called BuildConfig which is automatically generated by the build. This class is updated automatically by Android's build system (like the R class), and it contains a static final boolean called DEBUG, which is normally set to true.

How is BuildConfig generated?

There's a class called BuildConfig. java which is automatically generated by the build system. This class is updated automatically by Android's build system (like the R class). It already contains a static final boolean called DEBUG, which is normally set to true.


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.


Check for imports, sometimes BuildConfig is imported from any class of library unintentionally. For example:

import io.fabric.sdk.android.BuildConfig;

In this case BuildConfig.DEBUG will always return false;

import com.yourpackagename.BuildConfig;

In this case BuildConfig.DEBUG will return your real build variant.

p.s I just copy this one from my answer here:BuildConfig.DEBUG always false when building library projects with gradle