0

我正在尝试弯曲 Firebase 应用程序分发以使用 apk 拆分。我几乎拥有它,但是我的问题是

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

我的任务

task firebaseAllEnvRelease() {
        group = "publishing"

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

无论出于何种原因,firebase 任务在组装之前预先运行 apk 检查(而不是上传),所以显然 apk 不存在 - 我如何强制它尊重任务的顺序?

我知道 gradle 会创建它喜欢的任务图,但我确实有一个实用程序ordered,它将它们链接起来mustRunAfter,它肯定是正确的。

计划 b 是在此之前在单独的 gradlew 命令中运行 assemble,这可行,但是 -- 为什么:/

4

1 回答 1

0

问题是gradle插件

  1. 不声明对assemble任务的依赖(通常,无论 apk 拆分如何,按照 gradle 约定,你不应该只是“期望”apk 在那里)

  2. 不会为每个 apk 拆分生成任务——但你会为风味做

所以这是解决它的方法:

// 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()}"
}
}
}
于 2020-08-04T14:56:37.610 回答