Android - switching between Development and Production Web Services

android, java

Solution

I promised I'd do it and here it is:

- http://blog.blundellapps.com/switching-android-configurations-using-constants-and-ant/

- http://blog.blundellapps.com/running-an-ant-script-with-eclipse/

Also mirrored on GitHub: https://github.com/blundell/BuildChoiceTut

With the tutorial, you can switch configurations using Ant build scripts.

You setup a directory called /config/ in here you hold all your constants for different configurations. Once for each file i.e. live.props dev.props beta.props

Then, when Ant runs, it will read the selected file and 'inject' them into your build just before it is compiled.

Enjoy!

Problem

I want to have my app switch between development and production web services without changing too much in the code (and be relatively fool proof). Right now I have my web service addresses as `static final String` variables in the class that does the actual HTTP calls and switch code in the rest of the app by using a `static final boolean`. Now whereas the `boolean` is pretty convenient, I can't use it to change the web service addresses because they are themselves `static final` variables. What is the best practice for tackling this ? I found some discussions on SO that directed towards using Android SDK provided `debug` variable but although it can replace the `boolean`, it doesn't solve the other problem. NOTE: In case you are wondering, I'm using the web services class statically so I don't have a constructor in which I can check the `debug` variable and change variables, plus I'd also like them to be `static final`.

Original source