How to differentiate debug mode and release mode in android studio?
Hi, Recently I was find a solution to let the Android Studio able to determine whether the application is debug mode or release mode. So that I can easily switch the code inside the android so that the URL and link would be modified according to the debug/release mode.In the end , I found the solution and the method to add the variable/constant inside the gradle file so that the android code able to call it .
First of all, there are 1 variable inside the gradle call BuildConfig.DEBUG which is use to as the variable or toggle flag between the release mode and the debug mode.
If is the variable return true mean debug mode while false is release mode.
=| ok sorry for talk nothing on the variable that can be use on the android code which setting in gradle , we still haven't talk much about the variable which I will talk about it below.
Variable in gradle that can use on android java code
To use the variable or constant inside the gradle , first you have declare the value on the gradle file.
You could use the static member like BuildConfig to get the variable you want inside the gradle file.
Below is the example of put the value of you want inside the gradle file.
android {
buildTypes {
debug {
buildConfigField "String", "BASE_URL", "http://debug.server.com"
}
release {
buildConfigField "String", "BASE_URL", "http://release.server.com"
}
}
}
if is want to using the string variable for debug, could call using BuildConfig.debug , and vice versa if want to call release.
Nothing much to say now, if got any others question or better method , you could just give the comment thank you for reading. Have a nice days.
No comments:
Post a Comment