Is BuildConfig.DEBUG still listening?

According to this blog , BuildConfig.DEBUG was unreliable. Since my colleague makes extensive use of BuildConfig.DEBUG (it looks like test code in production code), I wonder how this flag is still listened to, as it was a few years ago.

+8
android
source share
3 answers

The problem you are referring to seems to be specific to ADT + Eclipse. Therefore, I believe that if you use Gradle and Android Studio, this should not be a problem.

Critical : this only happens if you use the Build Automatically option and you do not clear your project. Because of this, I’m unlikely to consider this a mistake. After all, who says what you need and should not rebuild when you make a code change and turn on automatic automatic tuning?

As a good practice, you should always clean and rebuild your project before the actual release, in which case this is not a problem.

So, this is still a problem if you use this option, rather than rebuilding your project before release, and you are still using ADT and Eclipse (which seems to be deprecated).

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

+7
source share

I can confirm that this error still exists, tested with Android Studio 1.2 Build AI-140.1782451 and Gradle 1.1, compiling with Android API level 21.

The problem is visible with 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 application in doubt, DEBUG remains false. This prevents me from debugging Retrofit, since I would like to enable it conditionally depending on the type of assembly.

+8
source share

I always had problems with a 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" } } 

In your code, you can read this variable:

  if (!MyApplication.get().getResources().getBoolean(R.bool.DEBUG)) { // Firebase Crash reporting FirebaseCrash.report(e); } 
+1
source share

All Articles