Fabric Beta和APK拆分 [英] Fabric Beta and APK splits
问题描述
我要基于ABI而不是密度来拆分我的应用,就像这样:
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
}
}
我有多种选择,有2种构建类型(调试和发布).我想将具有所有平台的本机库的通用apk文件放在Fabric beta上.据我了解,这是通过ext.betaDistributionApkFilePath属性支持的.
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.
我可以在buildType级别或flavor级别上定义它.问题是我需要构建类型和风格来获取我的变体-像这样:
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"
}
或
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?
推荐答案
对于每个现有变体,您可以添加将在Crashlytics任务之前执行的动作,并根据变体名称设置ext.betaDistributionApkFilePath
.就是这样的样子:
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
}
}
}
}
}
这篇关于Fabric Beta和APK拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!