Reputation: 5826
So im trying to figure out how i can setup compile flags in Eclipse so when im developing my Android applications i can make a specific build. Example i have a WebView based application and i want to be able to build a QA version which will have a different URL web.loadUrl("http://www.com");
I really don't want to have 2 projects QA and Release. I've been researching a way of bascially automizing this process. I dont want to have to go change the URL in the code each time before compiling and testing the application.
Upvotes: 4
Views: 1568
Reputation: 5497
In SDK Tools, Revision 17 (March 2012)
:
I find that the easiest way to accomplish what you want, is by checking the BuildConfig.DEBUG
boolean.
The DEBUG boolean is always true when developing
, only when you export a signed or unsigned apk, is it set to false
. You can use it as:
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";
}
Upvotes: 2
Reputation: 2053
Make the url string configurable, for example via properties file, which you can easily access with the help of java Properties. Ensure 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");
Upvotes: 3