BuildConfig.DEBUG always returns false

Why BuildConfig.DEBUG return false when I launch the application?

I use it to manage the log as shown below:

 public static void d(String LOG_TAG, String msg){ if(BuildConfig.DEBUG){ Log.d(LOG_TAG,msg); } } 
+15
source share
7 answers

In your Android Studio build option, are you using the debug option ?

This applies when you use flavors , either for debug or release .

in debug mode, BuildConfig.BUILD is true, and in release mode, false.

+6
source

Check the import in the class, make sure that you use the correct BuildConfig path. You can use BuildConfig not from your application, but from some library.

+41
source

If this code is in the library, it will always be false, thanks to a 3-year error in gradle .

+4
source

There is a problem with the problem:

applications

 dependencies { releaseCompile project(path: ':library', configuration: 'release') debugCompile project(path: ':library', configuration: 'debug') } 

Library

 android { publishNonDefault true } 
+2
source

Maybe not perfect, but in the end I created my own

  buildTypes { debug { buildConfigField "boolean", "IS_DEBUG", "true" // Had issues with BuildConfig.DEBUG, created IS_DEBUG to ensure functionality behaved as expected. } release { signingConfig signingConfigs.release buildConfigField "boolean", "IS_DEBUG", "false" } } 

And then refer to it as BuildConfig.IS_DEBUG programmatically.

+2
source

You may be importing the wrong package, check this out. (some Android libraries also have a BuildConfig class)

+2
source

I pointed out debuggable true in build.config, but that was always always false

After this change, everything worked correctly:

enter image description here

0
source

Source: https://habr.com/ru/post/1246215/


All Articles