Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android different packageName with flavors

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"                        
                }
            }
like image 293
Borja Avatar asked Jul 07 '16 10:07

Borja


People also ask

What are Android build types and product flavors?

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.

How to setup a new flavor for your Android app?

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.

What are the flavors of my sample app?

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.

What are “flavors?

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.


1 Answers

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.

like image 189
Krrishnaaaa Avatar answered Oct 05 '22 06:10

Krrishnaaaa