androidandroid-gradle-plugincrashlyticscrashlytics-betacrashlytics-android

Fabric Beta and APK splits


I'm splitting my app based on ABI, not on density, like so:

    splits {
       abi {
           enable true
           reset()
           include 'x86', 'armeabi', 'armeabi-v7a', 'mips', 'arm64-v8a'
           universalApk true
       }
    }

I have multiple flavors, and 2 build types (debug and release). I want to put the universal apk file, that has native libs for all platforms, up on fabric beta. From what I understand, this is supported through the ext.betaDistributionApkFilePath attribute.

I can define this either at the buildType level, or at the flavor level. The problem is I need both build type and flavor to pick up my variant - something like this:

android.applicationVariants.all { variant ->
   variant.ext.betaDistributionApkFilePath = "${buildDir}/outputs/apk/app-${variant.productFlavors[0].name}-universal-${variant.buildType.name}.apk"
}

or

gradle.taskGraph.beforeTask { Task task ->
if(task.name ==~ /crashlyticsUploadDistribution.*/) {
   System.out.println("task name: ${task.name}");
   android.applicationVariants.all { variant ->
       System.out.println("match: crashlyticsUploadDistribution${variant.name}");
       if(task.name ==~ /(?i)crashlyticsUploadDistribution${variant.name}/){
           ext.betaDistributionApkFilePath = "${buildDir}/outputs/apk/app-${variant.productFlavors[0].name}-universal-${variant.buildType.name}.apk"
           System.out.println(ext.betaDistributionApkFilePath);
       }
   }
}

Unfortunately this doesn't seem to work - is there any way to do this currently?


Solution

  • For every existing variant you can add an action that will execute before Crashlytics tasks and set ext.betaDistributionApkFilePath according to the variant name. That's how it looks like:

    android.applicationVariants.all { variant ->
      variant.outputs.each { output ->
        // Filter is null for universal APKs.
        def filter = output.getFilter(com.android.build.OutputFile.ABI)
    
        if (filter == null) {
          tasks.findAll {
            it.name.startsWith(
                "crashlyticsUploadDistribution${variant.name.capitalize()}")
          }.each {
            it.doFirst {
              ext.betaDistributionApkFilePath = output.outputFile.absolutePath
            }
          }
    
          tasks.findAll {
            it.name.startsWith(
                "crashlyticsUploadSymbols${variant.name.capitalize()}")
          }.each {
            it.doFirst {
              ext.betaDistributionApkFilePath = output.outputFile.absolutePath
            }
          }
        }
      }
    }