Fabric Beta and APK splits

感情迁移 提交于 2019-12-09 11:36:19

问题


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?


回答1:


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
        }
      }
    }
  }
}


来源:https://stackoverflow.com/questions/33488249/fabric-beta-and-apk-splits

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