In SDK Tools, Revision 17 (March 2012) :
- A function has been added that allows you to run some code only in debug mode. Builds now generates a BuildConfig class containing the DEBUG constant, which is automatically set according to your build type. You can check the constant (BuildConfig.DEBUG) in your code to run only debugging functions.
I find that the easiest way to accomplish what you want is to check the BuildConfig.DEBUG boolean.
Logical DEBUG is always true when developing , only when exporting a signed or unsigned apk is it set to false . You can use it like:
if (BuildConfig.DEBUG) { // Developing myURL = "http://www.bing.com"; } // Or the other way around: if (!BuildConfig.DEBUG) { // Released (signed app) myURL = "http://www.google.com"; }
source share