Android Studio: Check for a custom build type

Cowboy433 picture Cowboy433 · Mar 19, 2016 · Viewed 11.1k times · Source

I am trying to have a piece of code detect a BuildType, but I am a bit stuck. Whenever I type the code in for the IF statement, it says

Incompatible types. Required: Boolean. Found: java.lang.String

When I would have thought that it would have to be a string if there was .toString() at the end.

My code for detecting it is:

String buildtype = BuildConfig.BUILD_TYPE.toString();
if (buildtype = "admin") {
    //Do some admin stuff here.
}

I have set up the admin BuildType in my build.gradle file like this:

admin {
        debuggable true
        jniDebuggable false
        renderscriptDebuggable false
        minifyEnabled false
        zipAlignEnabled true
    }

Any help is greatly appreciated. Thanks

Answer

Mahmoud Abou-Eita picture Mahmoud Abou-Eita · Aug 21, 2016

What you can use in case you want to go for a custom build type and not a product flavor is:

if (BuildConfig.BUILD_TYPE.contentEquals("admin")) {
   // Do things related to the admin build type.
}