Android Studio: Check for a custom build type Android Studio: Check for a custom build type android android

Android Studio: Check for a custom build type


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.}


You can look at your BuildConfig file. It is the file you will get after creating a build.

For your question. I think you should use BuildConfig.FLAVOR instead of BuildConfig.BUILD_TYPE. And remember their type are String, so don't need to convert to String with .toString()

Lastly, you should use string compare method. So, your code should be

if (BuildConfig.FLAVOR.contentEquals("admin")) {    //Do some admin stuff here.}


Suppose you've

android {buildTypes {    release {        }    debug {    }    canary {    }    beta {    }}

In code, you can check something like

import com.yourpackagename.BuildConfigif (BuildConfig.BUILD_TYPE == "canary") {        Log.d("Build Type ","I'm canary")    }