6

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?

kimkevin
  • 2,202
  • 1
  • 26
  • 48

2 Answers2

11

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.

Viral Patel
  • 32,418
  • 18
  • 82
  • 110
  • I did the same and generated multiple apks from this window and when uploaded to play store it says that it is signed with a different certificate. All of my flavors have a different keystore file. Can you help? – Atif Rehman Feb 23 '17 at 07:53
8

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);
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • 1
    this is what I want, and I just found other way but I love it. thank you so much! – kimkevin Dec 22 '15 at 08:40
  • 1
    Nice, but won't the signing configs need to be preconfigured for this to generate signed apks? Just curious add I've never tried – Viral Patel Dec 22 '15 at 08:45
  • 2
    @Virus You can configure the signing config in your build.gradle script. For example check http://stackoverflow.com/questions/33645835/confused-with-signing-android-apk/33646119#33646119 or http://stackoverflow.com/questions/24263715/android-gradle-load-signing-config-from-external-file/24264879#24264879 – Gabriele Mariotti Dec 22 '15 at 09:46