I'm not sure, but it worked for me. If you want to execute the code according to the line (debug and release) in the application, you can do this with the following code.
This is for java activity file.
public void printMessage() { if (BuildConfig.DEBUG) { //App is in debug mode } else { //App is released } }
If you want to check the build.gradle file, run the following code.
First way
buildTypes { debug { buildConfigField "String", "SERVER_URL", '"http://test.this-is-so-fake.com"' } release { buildConfigField "String", "SERVER_URL", '"http://prod.this-is-so-fake.com"' } mezzanine.initWith(buildTypes.release) mezzanine { buildConfigField "String", "SERVER_URL", '"http://stage.this-is-so-fake.com"' } }
Second way
android { testBuildType obtainTestBuildType() } def obtainTestBuildType() { def result = "debug"; if (project.hasProperty("testBuildType")) { result = project.getProperties().get("testBuildType") } result }
See, this and this answer stackoverflow for more details.
I hope you get your decision.
source share