Nick Unuchek Nick Unuchek - 1 month ago 13
Android Question

How to determine debug build from gradle?

I want to switch String value for Debug and Release build in BuildConfig file:

def api= "\"api\"";

if (...){// What to set here to determine is build debug or not ?
api= "\"api-debug\"";
}


defaultConfig {
...
buildConfigField "String", "API", "${api}"
...
}

Answer

You should set multiple buildConfigFields in the scope of the buildTypes like so:

android {
    // ...
    buildTypes {
        debug {
            buildConfigField "boolean", "REPORT_CRASHES", "true"
        }
        // ...
    }    
}

For some more details see e.g. this article.

Comments