Reputation: 24005
What solution does Android offer for per environment configuration? In the web world, I am used to C# have config transforms and in Java web apps having a build that copies an appropriate .properties file into the WAR.
What is the solution to Android? Right now, I see alot of people just hard-coding static variables and changing them out when they want to build a production APK.
EDIT: Looking at similar questions, people suggest using SharedPreferences, but I do not understand this as it seems to be a Runtime object, and not a file. I am not looking for storing these values on startup, but instead having the app build with a certain set of properties from a configuration file.
Upvotes: 3
Views: 2138
Reputation: 111
1.) I recommend to use gradle to set up environment settings.
There is great plugin for Android: http://tools.android.com/tech-docs/new-build-system/user-guide
2.) Use "productFlavors" for environment settings.
Have a look at this: http://tulipemoutarde.be/2013/10/06/gradle-build-variants-for-your-android-project.html
Sample Config would be:
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
}
}
buildTypes {
debug {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
production {
packageName "com.sample.app"
}
staging {
packageName "com.sample.app.staging"
}
develop {
packageName "com.sample.app.develop"
}
}
}
Upvotes: 7