Executing a task after a signed bundle is created

人走茶凉 提交于 2021-01-27 06:00:52

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/52763570/executing-a-task-after-a-signed-bundle-is-created

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!