splits {
// Configures multiple APKs based on screen density.
density {
// Configures multiple APKs based on screen density.
enable true
reset()
// Specifies a list of screen densities Gradle should create multiple APKs for.
include 'ldpi', 'mdpi', 'hdpi', 'xhdpi', 'xxhdpi', 'xxxhdpi'
// Specifies a list of compatible screen size settings for the manifest.
//compatibleScreens 'small', 'normal', 'large', 'xlarge'
}
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs per ABI.
enable false
// 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 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
// Specifies that we do want to also generate a universal APK that includes all ABIs.
universalApk true //generate an additional APK that contains all the ABIs
//'armeabi' - Not surported by Realm since v2.0.0
}
}
我正在尝试通过Desity分割我的APK以减少APK大小,使用上面的Gradle它将APK分成密度,但每个APK的可绘制资源是相同的。
如果结果不是xhdpi APK只包含drawable-ldrtl-xhdpi-v17,drawable-xhdpi-v4和mipmap-xhdpi-v4?
答案 0 :(得分:0)
在gradle中分割的密度apk示例:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion = rootProject.ext.buildToolsVersion
defaultConfig {
versionCode 12
minSdkVersion 16
targetSdkVersion 20
buildConfigField "String", "FOO", "\"bar\""
}
splits {
density {
enable true
exclude "ldpi", "tvdpi", "xxxhdpi", "400dpi", "560dpi"
compatibleScreens 'small', 'normal', 'large', 'xlarge'
}
}
}
// map for the version code
ext.versionCodes = [all:1, mdpi:2, hdpi:3, xhdpi:4, xxhdpi:5]
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
def key = output.getFilter(OutputFile.DENSITY) == null ? "all" : output.getFilter(OutputFile.DENSITY)
output.versionCodeOverride = project.ext.versionCodes.get(key) * 100 + android.defaultConfig.versionCode
}
}