Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: How to generate multiple APKs or signed APKs for all productFlavors at once for a selected buildType?

I want to make all apk files for release to all stores, so I have to use a productFlavor for each apk:

build.gradle

buildTypes {
        release {
           ...
        }
        debug {
           ...
        }
    }

    productFlavors {
        red {
           ...
        }
        yellow {
           ...
        }
    }

outputs

appname_red_debug.apk
appname_red_release.apk
appname_yellow_debug.apk
appname_yellow_release.apk

and I know above codes can change apk's file name. But when I generate the signed apk, I have to choose only one productFlavor. This way, the result is only specific to that productFlavor.

: UPDATED

How can I make all apk files at once on commend line using assembleRelease? Is there anyone who knows about this?

like image 361
kimkevin Avatar asked Dec 22 '15 05:12

kimkevin


2 Answers

You can always select multiple flavors from the list when generating signed apk after selecting build type. It will generate apks for all selected flavors for the given build type. I've done this several times.

How, you ask? Select one flavor and press Ctrl + A to select all flavors or Press Ctrl and select multiple flavors as you want.

Here is an screenshot of me doing it right now (flavor names masked):

enter image description here

Update: I explored a bit more and noticed that dragging mouse to select multiple items doesn't work here as in other tools. This is the reason for all the confusion and I think Google should enable selection that way otherwise the feature may remain unused by many users.

like image 152
AndroidMechanic - Viral Patel Avatar answered Sep 24 '22 18:09

AndroidMechanic - Viral Patel


If you would like to use the command line you can use one of these commands:

 All buildVariants
 - ./gradlew assemble

 All flavors for a buildType
 - ./gradlew assembleDebug
 - ./gradlew assembleRelase

 All buildTypes for a flavor
 - ./gradlew assembleRed
 - ./gradlew assembleYellow

 Only a buildVariant
- ./gradlew assembleRedDebug
- ./gradlew assembleRedRelease    
- ./gradlew assembleYellowDebug
- ./gradlew assembleYellowRelease

Also you can change the apk name using

project.ext.set("archivesBaseName", "....");

For example

project.ext.set("archivesBaseName", "myApp."+ defaultConfig.versionName);
like image 22
Gabriele Mariotti Avatar answered Sep 22 '22 18:09

Gabriele Mariotti