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

    Build Types

  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?

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
Nakamura
  • 942
  • 2
  • 12
  • 23
  • BuildConfig class gets generated inside following path *"app/build/generated/source/buildConfig/yourBuildType/yourPackageName/BuildConfig.java"* – Jeel Vankhede Feb 12 '19 at 05:51
  • You should not make it consistent. because, it's generated class and it should be get generated upon every successful clean/re build. – Jeel Vankhede Feb 12 '19 at 05:52
  • @JeelVankhede 1. So the BuildConfig.BUILD_TYPE in code comes from what Android Studio injected when we run a build? 2. As a developer, we should rely on the buildTypes specified in build.gradle to config our Android Studio to match them. Correct? – Nakamura Feb 12 '19 at 06:02
  • Yes, that's correct, we can totally rely on BuildConfig class. But just to make you clear, Android studio doesn't inject anything but it's compiler which generates such classes. – Jeel Vankhede Feb 12 '19 at 06:05
  • @JeelVankhede Got it! I think this is a valid answer. Could you sum it and post an answer so I can accept it? – Nakamura Feb 12 '19 at 06:18

1 Answers1

1

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.


I.e. 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"'
        }
    }
. . .
}
Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58