How to Configure a Server URL inside an Android Client

When it comes to communication with a backend you often have different URLs for production and development.

One way to handle this for our Planets Android client is to generate different String resources. This can be done within your Gradle build file: build.gradle:

android {
  buildTypes {
    release {
      resValue 'string', 'serverUrl', '""'
    debug {
      resValue 'string', 'serverUrl', planetsUrl

The local variable planetsUrl can be configured within any Gradle file.

planetsUrl =

This will generate an additional resource within generated.xml:

<?xml version="1.0" encoding="utf-8"?>

    <!-- Automatically generated file. DO NOT MODIFY -->

    <!-- Values from build type: debug -->
    <string name="serverUrl" translatable="false"></string>


If you put this configuration into your global Gradle configuration you won't have a dirty workspace.

Show Comments