I am developing an Android application that interacts with server via REST APIs. Obviously I need to use different URL for development and release builds. Commenting and un-commenting code is very tedious and error pron.
Which is the best way to handle this situation? Using different build types in gradle file is one which could automate the process, but I am not sure if this is the right way to go.
There is also a possibility of increase in number of build types viz. test, internal-release etc.
If you are using Android Studio, use
buildConfigField
to add custom fields to yourBuildConfig
class.Here, I have three build types: the standard
debug
andrelease
, plus a custommezzanine
one. Each defines aSERVER_URL
field onBuildConfig
.Then, in Java code, you just refer to
BuildConfig.SERVER_URL
. That field will have a value based on what build type you used to build that particular edition of the app.