简体   繁体   中英

Compile Flags for Eclipse/Android development

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.

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");

In SDK Tools, Revision 17 (March 2012) :

  • Added a feature that allows you to run some code only in debug mode. Builds now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run debug-only functions.

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";
}

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