【问题标题】:APK split by density still contains all resources按密度拆分的 APK 仍然包含所有资源
【发布时间】:2017-07-04 14:19:55
【问题描述】:

我决定尝试使用 apk sliptting 来减小我的 apk 的大小。我将以下内容添加到我的 gradle 构建文件中

splits {

    // Configures multiple APKs based on screen density.
    density {

        // Configures multiple APKs based on screen density.
        enable true

        // Specifies a list of screen densities Gradle should not create multiple APKs for.
        exclude "ldpi"

        // Specifies a list of compatible screen size settings for the manifest.
        compatibleScreens 'small', 'normal'
    }
}

这成功地为各种密度生成单独的 apk。但是,我注意到所有的 apk 大小都一样,没有一个比通用 apk 小。因此,我将一个(app-hdpi-release.apk)加载到 apk 分析器中,发现它包含所有资源。没有一个被剥离。

因此,所有配置都有效地生成具有不同文件名的相同 apk。我错过了什么吗?是否有任何其他构建选项可能会阻止正在删除的资源?

【问题讨论】:

  • 您确定资源在drawable-xxx文件夹中的拆分正确吗?
  • 是的,它们也可以正常工作。我通过用不同颜色标记图像的不同密度版本并检查适当的版本是否在不同设备上显示来对此进行了测试。

标签: android gradle android-gradle-plugin


【解决方案1】:

我做了一些尝试和尝试,最后它接受了。在我仅根据屏幕密度进行拆分之前。然后我添加了标签 $compatibleScreens$ 并且它起作用了。

这是最后的分割块-

android {
  ...
  splits {

    density {
      enable true

      reset()
      include "mdpi", "hdpi", "xhdpi",     "xxhdpi"

      // This is the line of code which got it right
      compatibleScreens 'small', 'normal', 'large', 'xlarge'
    }
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 2010-11-13
    • 2020-05-03
    相关资源
    最近更新 更多