Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing a task after a signed bundle is created

Tags:

android

gradle

I would like to take the generated signed bundle from Android Studio and generate all apks and install them on every device that is connected to my computer at that time.

I know how to generate the apks and install them but I don't know how to run that script after a signed bundle is created. I only want this to run when I use Build -> Generate signed bundle/apk and choose a bundle and the production release flavor.

Can I do that with gradle?

Thanks.

like image 664
casolorz Avatar asked Oct 11 '18 15:10

casolorz


1 Answers

Android tasks are typically created in the "afterEvaluate" phase. Starting from gradle 2.2, those tasks also include "assembleDebug" and "assembleRelease". To access such tasks, the user will need to use an afterEvaluate closure:

 afterEvaluate {
       assembleDebug.dependsOn someTask    }

source: https://code.google.com/p/android/issues/detail?id=219732#c32

try add this in you app/build.gradle

afterEvaluate {
    assembleRelease.doLast {
        android.applicationVariants.all { variant ->
            if (variant.buildType.name == 'release') {
                def releaseBuildTask = tasks.create(name: "release") {
                    println("....................  test   ..............................")
                }
                releaseBuildTask.mustRunAfter variant.assemble
            }
        }
        println "build finished"
    }
}

invoke the build command and specify the task assembleRelease

./gradlew assembleRelease

like image 75
Marzi Heidari Avatar answered Oct 21 '22 12:10

Marzi Heidari