【发布时间】:2016-03-15 10:42:39
【问题描述】:
我面临这个似乎无法解决的问题。这是场景:
我正在构建使用 gradle 依赖的 apk,这种依赖是特定于架构的,所以对于 x86 的 apk,我需要不同的依赖,而 arm 也需要不同的依赖。
我用产品风味解决了这个问题:
productFlavors {
dev { ... }
develx86 { ... }
production { ... }
productionx86 { ... }
}
然后我这样定义依赖:
develCompile 'dependency_for_arm'
develx86Compile 'dependency_for_x86'
这很好用。但最近我不得不在我的应用程序中添加一个 renderscript 的用法。我是这样做的:
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
之后,当我在 Google Play 上上传 apk 时,它说它的 apk 适用于 arm、x86。我不知道这怎么可能。你可以认为它会在具有不同 CPU 的设备上崩溃(如果我为 arm 生成 apk 并且用户将在 x86 应用程序上执行它会崩溃)。
所以我决定使用 ABI 拆分:
splits {
abi {
enable true
reset()
include 'armeabi', 'x86'
universalApk false
}
}
//Ensures architecture specific APKs have a higher version code
//(otherwise an x86 build would end up using the arm build, which x86 devices can run)
ext.versionCodes = [armeabi:0, x86:1]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
int abiVersionCode = project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) ?: 0
output.versionCodeOverride = android.defaultConfig.versionCode + abiVersionCode
}
但是现在当我看到生成的 apk 文件时,我的 flavor-specific 依赖项没有包含在 apk 中,当我打开使用来自此依赖项的 API 的部分时,apk 将崩溃。
有人知道如何解决这个问题吗?或者有人知道为什么当我包含渲染脚本时 Google Play 说 apk 适用于两种架构? (没有它它可以正常工作,但我需要渲染脚本)。
感谢您的宝贵时间。我将不胜感激。
【问题讨论】:
-
运气好吗?找到答案后请留言
标签: android android-gradle-plugin build.gradle gradle-dependencies