Android Equivalent to web/app.config for multiple environments

1.3k views Asked by At

When working in .NET, I can use the web.config or app.config to set up multiple environments (Dev, Test, Production).

For example, I wish to specify the location of my web (restful) service for developing against one, testing against another, and then using the production url in the release version of the app.

How would I do something similar in Android?

EDIT: Without changing the url every time I release a version

1

There are 1 answers

0
Ollie C On BEST ANSWER

If you use a command like "android update project ...." in an Android project folder, you will get a build.xml file for Ant. Then you can do "ant release" and "ant debug" to do a full build, including signing with either the debug or release app cert (it's also easy to add obfuscation to the release process, or make other changes). See here for the documentation of the android command, and related commands.

Once the script is working you can run it via Eclipse or IntelliJ IDEA. So in my IntelliJ setup for example I can do a debug build through the IDE and run it straight on the device, or I can pick an Ant script to run, and the log shows in the IDE. So the benefits of Ant, but slightly neater than the command line, and the fact that the "android" command line tool can create the initial ant script makes it fairly easy to get up and running.

One caveat with the Android build process is that on Windows, don't use any spaces in the filename (or path) as the Android tools don't handle it. I had to rename a folder first time before it would work.

If you need to customise release/debug modes, or add others, you can do that by editing the ant script and rules.

For a tutorial on getting Ant up and running with an Android project see here