Gradle for Android offers buildConfigField
, allowing you to add arbitrary data members to the code-generated BuildConfig
class:
buildTypes {
debug {
buildConfigField "String", "SERVER_URL", '"http://test.this-is-so-fake.com"'
}
release {
buildConfigField "String", "SERVER_URL", '"http://prod.this-is-so-fake.com"'
}
mezzanine.initWith(buildTypes.release)
mezzanine {
buildConfigField "String", "SERVER_URL", '"http://stage.this-is-so-fake.com"'
}
}
In your Java code, you can refer to BuildConfig.SERVER_URL
, and it will be populated with the string based on the build type you choose at compile time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…