Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is BuildConfig.DEBUG still bugged?

Tags:

android

According to this Blog BuildConfig.DEBUG was unreliable. Since my colleague is using BuildConfig.DEBUG extensively (seemingly like test code in production code), I'm wondering if this flag is still as bugged as it was a few years ago.

like image 638
Someone Somewhere Avatar asked Feb 06 '15 19:02

Someone Somewhere


3 Answers

I can confirm this bug still exists, tested with Android Studio 1.2 Build AI-140.1782451 and Gradle 1.1 compiling against Android API Level 21.

The issue is visible with a Nexus 10 on Android 5.0.2 or a similar device.

If you open BuildConfig.DEBUG in the source editor it says:

public static final boolean DEBUG = Boolean.parseBoolean("true");

But if you debug the app under question, DEBUG stays on false. This hinders my Retrofit-debugging, as I wanted to enable it conditionally depending on the build-type.

like image 101
arne.jans Avatar answered Nov 08 '22 08:11

arne.jans


It seems the issue to which you are referring is specific to ADT + Eclipse. So I believe that if you're using Gradle and Android Studio, this should not be an issue.

Crucially: this only occurs if you're using the Build Automatically option, and you don't clean your project. Because of this, I would hardly consider this a bug. After all, who says what should and shouldn't be rebuilt whenever you make a code change and have Build Automatically enabled?

As a matter of good practice, you should always clean and rebuild your project prior to an actual release, in which case this is a non-issue.

So yes, this is still a problem if you're using this setting, and not rebuilding your project prior to release, and you're still using ADT and Eclipse (which seems to be destined for deprecation).

Here's the discussion of the bug: https://code.google.com/p/android/issues/detail?id=27940

like image 30
Sam Dozor Avatar answered Nov 08 '22 08:11

Sam Dozor


I had always problems with the predefined variable, so I created my own:

  buildTypes {
        // If we use the same keystore for debug and release, we don't have to wipe all preferences
        debug {
            //noinspection GroovyAssignabilityCheck
            signingConfig signingConfigs.releaseConfig
            zipAlignEnabled true

            resValue "bool", "DEBUG", "true"
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //noinspection GroovyAssignabilityCheck
            signingConfig signingConfigs.releaseConfig
            zipAlignEnabled true

            resValue "bool", "DEBUG", "false"
        }
    }

I your code you can read this variable:

    if (!MyApplication.get().getResources().getBoolean(R.bool.DEBUG)) {
        // Firebase Crash reporting
        FirebaseCrash.report(e);
    }
like image 33
Denny Weinberg Avatar answered Nov 08 '22 06:11

Denny Weinberg