Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying multiple build variants at a time - Android studio gradle

I recently discovered this awesome feature about gradle productFlavors. I currently have 3 variants (staging, sandbox and production) and I can deploy one of the variants at a time using build variant panel.

Is there a way I can deploy all variants at a time?

like image 563
user1051505 Avatar asked Dec 12 '22 04:12

user1051505


2 Answers

Yes, In Android Studio, open the "Gradle Tasks" tab, which is usually on the right. You will see many tasks that start with 'assemble', double click on one of those.

For example, double clicking on 'assembleRelease' will create all your release apks.

From the docs:

Building and Tasks

We previously saw that each Build Type creates its own assemble task, but that Build Variants are a combination of Build Type and Product Flavor.

When Product Flavors are used, more assemble-type tasks are created. These are:

1) assemble[Variant Name]

2) assemble[Build Type Name]

3) assemble[Product Flavor Name]

1) allows directly building a single variant. For instance assembleFlavor1Debug.

2) allows building all APKs for a given Build Type. For instance assembleDebug will build both Flavor1Debug and Flavor2Debug variants.

3) allows building all APKs for a given flavor. For instance assembleFlavor1 will build both Flavor1Debug and Flavor1Release variants.

The task assemble will build all possible variants.

like image 81
MikeWallaceDev Avatar answered Apr 09 '23 13:04

MikeWallaceDev


If you know the names of the gradle tasks that install your variants you can run this from the root of your project in the terminal:

./gradlew install{VariantName1, VariantName2, VariantName3}Debug

This assumes you have a module build.gradle file with variants set up according to the guide. So something along these lines:

apply plugin: 'com.android.application'

android {

    ...

    flavorDimensions "myFlavorDimension"
    productFlavors {
        VariantName1 {
            ...
        }
        VariantName2 {
            ...
        }
        VariantName3 {
            ...
        }
    }
    
    ...

}

dependencies {
    ...
}

You can find these gradle task names either in Android Studio in the Gradle Tab (right side of GUI) under you moduleName->Tasks->install

Or you can find them in the terminal with:

./gradlew tasks | grep install

I'm sure there is some Regex that could grab only the ones of interest programmatically as well, but I'm not a regex buff. If you want to leave a comment with something that would work, I'd be happy to edit and add later.

like image 20
topher217 Avatar answered Apr 09 '23 14:04

topher217