Accepted answer

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.


i've seen some strange behavior that has to do with when the values in buildconfig are set to their final values. this may have something to do with your issue.

the simple explanation is that default values are set initially before proguard is run, then after proguard runs, the buildconfig file is regenerated with the proper values. however, proguard has already optimized your code by this point and you have issues.

here is a bug i created against gradle.


will you check your app level build.gradle enable debuggable true for release

buildtypes {
    release {
        debuggable true

instead you keep false or comment that line

buildtypes {
    release {
        //debuggable true

now you will get buildconfig.debug false for release build


does not work properly as far as i understood (android issue 22241)

i had some trouble on a project (working with eclipse), that constant was not set to true when exporting a signed apk of my project :(

would love to hear it works though


a good way is creating your own class :

public class log {

public static void d(string message) {
    if (buildconfig.debug)
            "[" + (new exception().getstacktrace()[1].getclassname()) + "]",
            "{" + (new exception().getstacktrace()[1].getmethodname()) + "} "
            + message



i would want to propose a simple workaround if you use proguard during apk export.

proguard provides a way to remove calls to specific functions in release mode. any calls for debugging logs can be removed with following setting in proguard-project.txt.

# remove debug logs
-assumenosideeffects class android.util.log {
    public static *** d(...);
    public static *** v(...);

and optimization setting in


with this, you don't need to concern any unnecessary string computation passing to debug log to which @jeremyfa pointed. the computations are just removed in release build.

so the workaround for buildconfig.debug uses the same feature of proguard like following.

public class debugconfig {

    private static boolean debug = false;

    static {
        setdebug(); // this line will be removed by proguard in release.

    private static void setdebug() {
        debug = true;

    public static boolean isdebug() {
        return debug;

and following setting in proguard-project.txt.

-assumenosideeffects class com.neofect.rapael.client.debugconfig {
    private static *** setdebug();

i would prefer using this to disabling the build automatically option, because this doesn't depend on the builder's individual ide setting but is maintained as committed file which are shared among developers.


from preparing for release:

turn off logging and debugging

make sure you deactivate logging and disable the debugging option before you build your application for release. you can deactivate logging by removing calls to log methods in your source files. you can disable debugging by removing the android:debuggable attribute from the tag in your manifest file, or by setting the android:debuggable attribute to false in your manifest file. also, remove any log files or static test files that were created in your project.

also, you should remove all debug tracing calls that you added to your code, such as startmethodtracing() and stopmethodtracing() method calls.

more information is following the link.


the solution for me:

  1. project -> build automatically
  2. project -> clean
  3. project -> build
  4. project export android application

it's work in r20


it does work, but note that the code file never changes, even when exporting the signed file. the export process changes the value of this variable to false, which might give you the false impression that it is not working. i tested this with logging statements like

if (com.mypackage.buildconfig.debug)
            log.d(tag, location.getprovider() + " location changed");

when testing, my log statements no longer produce any output.


check for imports, sometimes buildconfig is imported from any class of library unintentionally. for example:


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


it doesn't work properly:

issue 27940: buildconfig.debug is "true" for exported application package

it's disappointing that they sometimes release buggy features.


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 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.

Related Query

More Query from same tag