I'd like to be able to build and install multiple versions of my app (concurrently), targeting different environments such as Development, Staging and of course Production.
The package name in the AndroidManifest.xml
seems to be the major hurdle here, as it is what uniquely identifies the app. I thought it would be possible to simply switch between com.mydomain.prod
, com.mydomain.staging
and com.mydomain.dev
or some sort of similar convention but so far I've had no luck coming up with a package structure that works for this approach.
What strategy can I employ to do this with as little pain as possible?
Once the new project is created, by default it consists of two build types/variants - debug, release. Debug is the build type that is used when we run the application from the IDE directly onto a device. A release is the build type that requires you to sign the APK.
Each module has its own build file, so every Android Studio project contains two kinds of Gradle build files.
With Gradle you can specify different "flavors" of your application. This is done in your build.gradle
:
android {
// …
defaultConfig {
// …
}
productFlavors {
prod
applicationId "com.mydomain.prod"
}
staging {
applicationId "com.mydomain.staging"
}
dev {
applicationId "com.mydomain.dev"
versionCode 2
}
}
}
Each flavor properties are inherited from defaultConfig
.
Now, in the src
directory of your app, you can create directories with flavor-specific code/resources in it:
app/
|-- src/
|-- main/
|-- prod/
|-- staging/
|-- dev/
These links might be useful:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With