Firebase App Distribution with apk splits unable to find apk

 ̄綄美尐妖づ 提交于 2021-02-11 17:05:06

问题


I'm trying to bend firebase app distribution to work with apk splits. I almost have it, however my issue is this

Could not find the APK. Make sure you build first by running ./gradlew assemble[Variant], 
or set the apkPath parameter to point to your APK

My task

task firebaseAllEnvRelease() {
        group = "publishing"

        dependsOn ordered(
                ":printVersionCode",
                ":foo:app:assembleAllRelease"
                ":foo:app:firebasePublishAllEnvRelease")
    }

For whatever reason, the firebase task runs the apk check (not upload) beforehand, before assemble, so obviously the apk is not there -- how can I force it to respect the order of tasks?

I know gradle creates the tasks graph hopwever it likes, but I do have a utility ordered for what, which chains them via mustRunAfter and it is for sure correct.

Plan b is to run the assemble ina separate gradlew command before that, that works but -- why :/


回答1:


The problem is that the gradle plugin

  1. doesn't declare dependency on assemble task (in general, regardless of apk splits, by gradle convention, you shouldn't just "expect" the apks to be there)

  2. doesn't generate tasks per apk splits -- but you do for flavors

So here is the work around for it:

// Generate firebase app distribution task variants for all abis
applicationVariants.all { variant ->
variant.outputs.all { output ->
def abi = output.getFilter(com.android.build.OutputFile.ABI)

if (abi == null) return
def abiName = abi.replace("_", "").replace("-", "")
task("appDistributionUpload${abiName.capitalize()}${variant.name.capitalize()}", type: com.google.firebase.appdistribution.gradle.UploadDistributionTask_Decorated) {
appDistributionProperties = new com.google.firebase.appdistribution.gradle.AppDistributionProperties(
new com.google.firebase.appdistribution.gradle.AppDistributionExtension(),
project,
variant
)
appDistributionProperties.apkPath = output.outputFile.absolutePath
appDistributionProperties.serviceCredentialsFile = project.file("secrets/ci-firebase-account.json")
appDistributionProperties.releaseNotes = abi
appDistributionProperties.groups = "ra-testers"
 
// Add dependsOn respective assemble task, so it actually
// builds apk it wants to upload, not just expect it to be there
dependsOn "assemble${variant.name.capitalize()}"
}
}
}


来源:https://stackoverflow.com/questions/62887447/firebase-app-distribution-with-apk-splits-unable-to-find-apk

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