android - Android Studio在密度上拆分了APK

标签 android gradle split apk

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?

最佳答案

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
  }
}

关于android - Android Studio在密度上拆分了APK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42528582/

相关文章:

android - vCard 的二维码导入不分隔字段。是格式吗?

具有水平滑动的 Android StackView 布局类型

kotlin - Kotlin Gradle对它的项目家感到困惑

c#拆分动态数组

Java Split 没有按预期工作

android - 获取对托管 ProgressDialog 的引用

c++ - Android NDK 与 Gradle 中的 OpenCV 原生集成

android - Buck - 构建具有多种 Gradle 风格/构建类型和 list 的 Android 应用程序

python - Pandas 数据框列删除第一个特定字符之前的字符串

android - 应用于嵌套 fragment 的 fragment 间通信?