简体   繁体   中英

Where are build types of the app defined?

  1. I know we can edit build types in Android Studio:

    构建类型

  2. I know we can edit each build type setting in gradle:

     android { buildTypes { release { minifyEnabled true } }
  3. I know we can detect build types in code. How do I detect if I am in release or debug mode?

But where actually are the build types defined? Let say I want to commit it to git. What should I do to keep build types of the project consistent?

Where actually are the build types defined?

Basically, BuildConfig is the auto-generated class that resides under path :

app/build/generated/source/buildConfig/yourBuildType/yourPackageName/BuildConfig.java .

This class holds variables provided by buildTypes {} block from app level build.gradle file. So, on every clean & rebuild of project, Gradle auto generates BuildConfig class that can be used in further Android development environment .


Ie BuildConfig.DEBUG is the default variable that we can use in our application code to determine it's buildType .

We can provide our own fields through buildType from build.gradle file like following:

android {
. . .
    buildTypes {
        debug {
            buildConfigField "String", "SOME_VARIABLE", '"This string value is from build config class"'
        }
    }
. . .
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM