How to trigger gradle task assembleAndroidTest twice in the gradle with custom task or plugin with different input parameters?

33 Views Asked by At

I need to build android test APK twice with different appId for library project. After that I can submit 2 APKs to Firebase Test Lab as the test apk and application apk.

To achieve that I wish to run assembleAndroidTest twice with configurable appId parameter. Manually it looks like that gradle assembleAndroidTest and gradle assembleAndroidTest -DappId=somedifferentappid

Then I can upload the 2 APKs to the test lab easily and run the tests.

Currently I stuck in the gradle task configuration because gradle doesn't allow depending on the same task twice. So I cannot trigger the same assemble task after I change some properties

tasks.register("assembleLibraryApk"){
    project.ext.properties["appId"] = null
    dependsOn("assembleAndroidTest")
    //rename APK
}
tasks.register("assembleTestApk"){
    project.ext.properties["appId"] = "somedifferentappid"
    finalizedBy("assembleAndroidTest")
}
tasks.register("buildNeededApks"){
    dependsOn("assembleLibraryApk")
    finalizedBy("assembleTestApk")
}

I have tried to create custom tasks and custom plugins with differnet inputs. However, I received or cycle dependency problem or assembleAndroidTest task executed only once.

0

There are 0 best solutions below