现在可以了,请参阅此链接。
https://developer.android.com/studio/build/configure-apk-splits.html
更新 :
您需要在 android 标签内的模块级 build.gradle 中添加以下代码:
splits
{
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable true
// By default all ABIs are included, so use reset() and include to specify that we only
// want APKs for x86, armeabi-v7a, and mips.
// Resets the list of ABIs that Gradle should create APKs for to none.
reset()
// Specifies a list of ABIs that Gradle should create APKs for.
include "x86", "armeabi-v7a", "mips"
// Specifies that we do not want to also generate a universal APK that includes all ABIs.
universalApk false
}
}
这将为您提供多个 apk 以针对不同的架构上传。根据安卓:
不同的 Android 手机使用不同的 CPU,这反过来又支持不同的指令集。CPU 和指令集的每种组合都有其自己的应用程序二进制接口或 ABI。ABI 非常精确地定义了应用程序的机器代码在运行时应该如何与系统交互。
另外,请记住使用不同的 versionCode 推送两个 apk。一种方便的方法是使用以下脚本,稍后在同一网址上提供:
// Map for the version code that gives each ABI a value.
ext.abiCodes = ['armeabi-v7a':1, mips:2, x86:3]
// For per-density APKs, create a similar map like this:
// ext.densityCodes = ['mdpi': 1, 'hdpi': 2, 'xhdpi': 3]
import com.android.build.OutputFile
// For each APK output variant, override versionCode with a combination of
// ext.abiCodes * 1000 + variant.versionCode. In this example, variant.versionCode
// is equal to defaultConfig.versionCode. If you configure product flavors that
// define their own versionCode, variant.versionCode uses that value instead.
android.applicationVariants.all { variant ->
// Assigns a different version code for each output APK
// other than the universal APK.
variant.outputs.each { output ->
// Stores the value of ext.abiCodes that is associated with the ABI for this variant.
def baseAbiVersionCode =
// Determines the ABI for this variant and returns the mapped value.
project.ext.abiCodes.get(output.getFilter(OutputFile.ABI))
// Because abiCodes.get() returns null for ABIs that are not mapped by ext.abiCodes,
// the following code does not override the version code for universal APKs.
// However, because we want universal APKs to have the lowest version code,
// this outcome is desirable.
if (baseAbiVersionCode != null) {
// Assigns the new version code to versionCodeOverride, which changes the version code
// for only the output APK, not for the variant itself. Skipping this step simply
// causes Gradle to use the value of variant.versionCode for the APK.
output.versionCodeOverride =
baseAbiVersionCode * 1000 + variant.versionCode
}
}
}
This goes below the splits code. This gives you multiple apks with your orignal version code multiplied by the architecture code given in abiCodes array in the script above. Eg : if your version code is 5, the mips builds code would be 2005. A universal apk will also be created if you universalApk is true in splits code. The can be a fallover apk in case no architecture build apk is found for a certain device.