在谷歌市场发布应用的时候,有时候由于apk太大,需要分abi或者screen,对于不同的机种,打不同的apk包,来减少apk的大小
而谷歌市场的发布,支持如下种类的多apk发布:
对于一个应用,要支持多apk,需要apk的签名和app id一致,而Version code必须不同
用AS,可以通过如下gradle代码达到这个目的,参考 https://developer.android.com/studio/build/configure-apk-splits.html
多apk abi示例:
apply plugin: 'com.android.application' android { compileSdkVersion xx buildToolsVersion "xxx" defaultConfig { //...... } buildTypes { //... } splits { abi { enable true reset() include 'armeabi', 'armeabi-v7a','arm64-v8a','x86_64','mips' // universalApk true } } }
接下来一段是对打出来的多个apk包,设置不同的versionCode,基本是原文照抄
ext.abiCodes = ['armeabi':1, 'armeabi-v7a':2, 'arm64-v8a':3,'mips64':4,'mips':5,'x86':6,'x86_64':7] import com.android.build.OutputFile //https://developer.android.com/studio/build/configure-apk-splits.html // // 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 } } }
对于打出来的多个apk包,假设基本的versionCode为1,则他们的versionCode为1001,2001,3001,4001等等
接下来,可以对这多个同一应用的多个apk,发布到google市场了