简体   繁体   中英

How to forcefully cause compilation error of debugging code only for the build release?

When I develop app, I frequently add some bits of code for debugging/dev-t purposes. Unfortunately, I also tend to forget these bits of code, when I create release APK. I would like to use some solution to invoke compilation error only for release build.

Any well-known solution or some new idea for that? This would be the best forgetfulness-proofing my development :)

You can user variables from BuildConfig such as Debug (returns boolean) or FLAVOR if you would like to throw error for different flavor value.

Better solution is to place your DEBUG code in structure like this:

if(BuildConfig.DEBUG){
  //place your debug code here
}

And you will do not need to remove it. If you still need to throw information in non debug build to remove that just check if BuildConfig.DEBUG is false and throw an exception.

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