简体   繁体   中英

Why is BuildConfig.DEBUG still true if app isn't launched using the debug button?

I am trying to launch my application in debug mode by using the little debug icon on the right of the run icon. i assumed this is the way to start debug mode.

The problem is that i am checking BuildConfig.DEBUG to see if i am in debug mode but it's always true and when i want to check in generated build.config file i found: public static final boolean DEBUG = Boolean.parseBoolean("true");

My question is: am i doing something wrong in launching debug? is it not the way we do it? how can i use debug mode?

You're confusing debugging with a debug build.

BuildConfig.DEBUG is an indication of whether or not your app is a debug build or a release build, it doesn't have anything to do with launching the app to debug. Even launching the app by just running it will also have BuildConfig.DEBUG as true, because it's still a debug build, this will only change once you actually create a signed release.

The icon you're referring to attaches the android debugger to the process, allowing you to use breakpoints, but it generates the same output as it would by simply running the app as well.

BuildConfig.DEBUG will only be false once you create a signed release build, so it has nothing to do with launching the app to debug

Thanks to Adam Burley's comment that lead me to figure out why my build always had BuildConfig.DEBUG = true , even when doing a signed release build.

If you have either of the following set for a buildType in your build.gradle :

testCoverageEnabled true
debuggable true

Then your DEBUG value will be true for that buildType, no matter if it's a signed release build or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM