In Android Studio I created two configurations:
How can I determine in code which configuration I selected?
I know that there is buildConfigField
in /app/build.gradle
but the names of the buildTypes
do not correspond to the configuration
names, so I wonder how does that all fit together.
android {
...
defaultConfig {
...
}
buildTypes {
debug {
...
buildConfigField 'boolean', 'DEBUG', 'true'
}
release {
...
}
}
}
I assume that in Android Studio a configuration
corresponds to a schema
in Xcode and a buildConfigField
corresponds to the Environment Variable
in Xcode (me coming from iOS world).
You don't, insofar as a run configuration is an IDE thing, not an Android thing.
None of that has anything to do with run configurations. Run configurations are for configuring what is to be run:
app
app
something
librarydebug
versusrelease
are build types, one dimension of the build variant. You choose which build variant the run configurations use via the Build Variants tool, docked by default on the lower-left side of the Android Studio IDE window.To have different code behavior based upon
debug
versusrelease
, you can:Examine
BuildConfig.BUILD_TYPE
, which will be eitherdebug
orrelease
Use
buildConfigField
to inject values intoBuildConfig
from Gradle, based upon build type and/or product flavorUse
resConfig
to inject values into resources, such as string resourcesUse custom source sets per build type (e.g.,
src/main/
for your common code,src/debug/
for debug-specific code,src/release/
for release-specific code)