Flags compilation for Eclipse / Android development

So, I'm trying to figure out how I can set up compilation flags in Eclipse, so when I develop my Android applications, I can make a specific assembly. Example I have a WebView-based application, and I want to be able to create a version of QA that will have a different URL web.loadUrl("http://www.com"); I really don't want to have 2 QA and Release projects. I studied the basic automation of this process. I do not want to change the URL in the code each time before compiling and testing the application.

+4
source share
2 answers

Set the url string configuration, for example, through a properties file, which you can easily access with java Properties . Make sure you do not need to recompile the application if you want to change the URL.

 Properties applicationConfiguration = new Properties(); applicationConfiguration.load(this.getClass().getResourceAsStream("application.properties")); String url = applicationConfiguration.getProperty("my.url", "http://defaulurl.com"); 
+3
source

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"; } 
+2
source

All Articles