I need to install 2 versions of my project (Production and Development). I need 2 apps. I'm trying to achive it by using flavors, but when I sign the apk, it always generate the same app, with the same packageName (com.company.project). I've tried removing the applicationId from the defaultConfig but it doesn't work neither.In the manifest, the package name is com.company.project.
Anyone knows how to do that?
This is the build.gradle
defaultConfig {
multiDexEnabled true
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
applicationId "com.company.project"
}
productFlavors {
development {
applicationId
"com.company.project.DEV"
versionName "1.0-dev"
resValue "string", "app_name", "Project-Dev"
}
production {
applicationId
"com.company.project.PROD"
resValue "string", "app_name", "Project-Prod"
versionName "1.0-prod"
}
}
Android product flavors also known as Android build types or Android build variants are the native Android app development way to implement different versions of the same application with minor changes provided by Gradle and Android Studio together. Here is the official Android documentation for configuration of Android product flavors.
You can edit the flavor name, applicationID, and add a new signing config, among others. Click OK when you are done. A gradle sync should occur, and when it’s finished, you have successfully setup a new flavor for your app. Take special note of the applicationID.
For our sample app, we have defined three flavors, blueberry, chocolate and raspberry. To see the definitions of each flavor, open your app build.gradle file. We have changed the applicationID, so all three flavors can exist on the same device at the same time, as well as modified the minimum and target SDK versions.
This is called “flavors.” Using multiple flavors, a developer/team can easily build different versions of a single app, but easily customized to keep similarities and allow divergence as and when necessary.
When you create productFlavors
then the corresponding gradle
tasks also changes.
For instance, originally you have only assembleDebug
and assembleRelease
. But, after implementing productFlavors
, the gradle
tasks will change. Taking your example in consideration, it will be
assembleDevelopmentDebug
assembleDevelopmentRelease
assembleProductionDebug
assembleProductionRelease
If you are using Android Studio
, then you do not have to worry about the gradle
tasks. Just select the Build Variant
from the menu and build the project. It will run the corresponding gradle tasks and install the build.
I have written a blog explaining this, Product Flavors in Android. A sample project is also available on GitHub.
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