gpt4 book ai didi

android - "minifyEnabled"与 "shrinkResources"- 有什么区别?以及如何获得节省的空间?

转载 作者:IT老高 更新时间:2023-10-28 13:23:32 33 4
gpt4 key购买 nike

背景

根据 Andriod 文档 (here) 的“资源缩减”网页,您可以通过 build.gradle 文件最小化应用程序的大小,使用以下几行:

android {
...

buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

而且,他们说在使用的时候,它还会告诉你在这个过程中节省了多少:

When you enable shrinkResources, building your app should display output like the following during the build:

... Removed unused resources: Binary resource data reduced from 2570KB to 1711KB: Removed 33%

问题

我找不到这些问题的答案:

  1. 使用 Android-Studio 本身创建签名应用时,我在哪里可以找到保存了多少以及删除/修改了哪些文件的信息?
  2. “shrinkResources”究竟做了什么而“minifyEnabled”却没有?为什么“shrinkResources”依赖于“minifyEnabled”?
  3. 这些选项是否会影响图像文件的大小和/或质量?
  4. Proguard 不负责压缩源代码吗?我问这个是因为它说“你必须启用 minifyEnabled 才能打开代码收缩”,

最佳答案

让我们看看

When using Android-Studio itself to create the signed app, where can I find the information of how much was saved and which files were removed/modified?

这些将在 gradle 日志中。在 Android Studio 中,我相信这些都显示在 Messages 窗口中(在 Android、Run、TODO 窗口旁边)。

What exactly does "shrinkResources" do that "minifyEnabled" don't? And why do "shrinkResources" depend on "minifyEnabled" ?

minify 运行 ProGuard。 shr​​ink 移除 ProGuard 标记为未使用的资源。

Do any of those options affect the size and/or quality of image files?

不!

Isn't Proguard responsible of shrinking source code? I ask this because it says "you have to enable minifyEnabled in order to turn on code shrinking,"

ProGuard 缩小 CODE ONLYshr​​inkResources 它只是 /res/ 文件夹中的东西。 shr​​inkResources 依赖于 ProGuard 的日志输出来运行。 ProGuard 是真正分析代码以了解未使用的代码的人。

编辑:

我刚刚发现了一篇非常不错的博文。 CommonsWare 将其发布在其他一些 stackOverlow 问题上:http://cyrilmottier.com/2014/08/26/putting-your-apks-on-diet/

它完美地解释了你的后续问题:

why would one depend on the other?

来自帖子:

Proguard works on the Java side. Unfortunately, it doesn’t work on the resources side. As a consequence, if an image my_image in res/drawable is not used, Proguard only strips it’s reference in the R class but keeps the associated image in place.

这意味着,shr​​inkResources 仅比较可绘制对象是否在文件夹中,而不是在 R 类中。

关于android - "minifyEnabled"与 "shrinkResources"- 有什么区别?以及如何获得节省的空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30800804/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com