Configuring Gradle
Android studio uses new build system called Gradle. We can use it to build project and configure server urls, settings or replace assets. 1. Following example shows build.gradle file to change server url depending upon the build flavor. I am using two flavors 1. devel 2. prod. For simplicity I shall keep it simple without configuring it for signing. Both flavors define a config variable "HOST" with different value to be used, when apk is built. If developer chooses, to have "devel" build, it will come with "http://192.168.1.34:3000" as HOST. productFlavors { devel { buildConfigField 'String', 'HOST', '"http://192.168.1.34:3000"' } prod { buildConfigField 'String', 'HOST', '"http://api.zuul.com"' } } To access the config constant use following code. String string = BuildConfig.HOST; 2. Following example shows how t...