In a team project, we encountered one of the common problems connected with mobile applications. Android application sends requests to backend web service and we don’t have backend web service deployed right now on a separate server, so every mobile developer is compiling and running backend web service on the local machine for testing purposes. In the beginning, url of backend url looked as follows:

Of course address varies on different machines.

When every developer was pushing changes, configuration of the backed url changed as well. It became annoying, so we decided to do something about that.


Attempt #1

First, we came with an idea of ignoring local changes of the XML file, which contains backend url address.
It can be done via Git in the following way:

git update-index --assume-unchanged [<file>...]

We can undo this operation with such command:

git update-index --assume-unchanged [<file>...]

We can also add ignored alias to our .gitconfig file:

ignored = !git ls-files -v | grep "^[[:lower:]]"

Then we can type: git ignored to display ignored files.

For more information check StackOverflow discussion.

This solution is kind of work-around, so we decided to do it better.

Attempt #2

We could create alias for backend url and replace it before compilation dynamically via Gradle.

Our new configuration file res/values/configuration.xml looks like that:

Then, our build.gradle file needed to be updated. The most important part starts in 29th line, where #const_backend_url# value is replaced with an IP address of the local machine, where mobile application is compiled. As I mentioned before, backend web service application is compiled on the same machine, so backend web service address will be proper in that case for testing purposes.

Similar trick was applied in project: in file, so you can check it out.