Saad Farooq Saad Farooq - 1 year ago 63
Android Question

Android - switching between Development and Production Web Services

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
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
variable but although it can replace the
, 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
variable and change variables, plus I'd also like them to be
static final

Answer Source

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

Also mirrored on GitHub:

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.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download