Search code examples
firebasefirebase-app-distributionapp-distribution

Distributing APK splits with Firebase App Distribution


“Is it possible to use Firebase App Distribution with APK split? It doesn't declare a dependency on assemble task, are there any workarounds for this?"


Solution

  • The problem with the gradle plugin is that it

    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

    Try the following work around:

    // 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()}"
    }
    }
    }