"minifyEnabled";与"shrinkResources" - 有什么不同?以及如何获得节省的空间? [英] "minifyEnabled" vs "shrinkResources" - what's the difference? and how to get the saved space?
问题描述
根据Andriod文档的资源缩减"网页(此处 ),您可以使用以下几行通过build.gradle文件来最小化应用程序的大小:
According to the "Resource Shrinking" webpage of Andriod documentations (here), you can minimize the app's size via the build.gradle file, by using these lines:
android {
...
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
而且,他们说使用它时,它还会告诉您在此过程中节省了多少:
And, they say that when using it, it will also tell you how much is saved in the process:
启用收缩资源后,构建应用程序应显示 在构建过程中,输出如下所示:
When you enable shrinkResources, building your app should display output like the following during the build:
... 删除未使用的资源:二进制资源数据从2570KB减少到 1711KB:已删除33%
... Removed unused resources: Binary resource data reduced from 2570KB to 1711KB: Removed 33%
问题
我找不到这些问题的答案:
The questions
I can't find out the answers to those questions:
- 使用Android-Studio本身创建签名的应用程序时,在哪里可以找到保存了多少文件以及删除/修改了哪些文件的信息?
- "shrinkResources"和"minifyEnabled"到底没有什么作用?为什么"shrinkResources"依赖于"minifyEnabled"?
- 这些选项中的任何一个会影响图像文件的大小和/或质量吗?
- Proguard是否不负责缩小源代码?我问这个问题是因为它说:必须启用minifyEnabled才能打开代码收缩功能."
推荐答案
让我们看看
在使用Android-Studio本身创建签名的应用程序时,在哪里可以找到保存了多少信息以及删除/修改了哪些文件的信息?
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窗口旁边)中.
Those are gonna be in the gradle log. Inside Android studio I believe those are shown in the Messages
window (next to Android, Run, TODO windows).
"shrinkResources"和"minifyEnabled"没有什么作用?为什么"shrinkResources"依赖于"minifyEnabled"?
What exactly does "shrinkResources" do that "minifyEnabled" don't? And why do "shrinkResources" depend on "minifyEnabled" ?
minify
运行ProGuard. shrink
删除ProGuard标记为未使用的资源.
minify
runs ProGuard. shrink
remove resources that ProGuard flagged as unused.
这些选项中的任何一个会影响图像文件的大小和/或质量吗?
Do any of those options affect the size and/or quality of image files?
不!
Proguard是否不负责缩小源代码?我问这个问题是因为它说:必须启用minifyEnabled才能打开代码收缩功能."
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缩小仅代码; shrinkResources
只是/res/
文件夹中的内容. shrinkResources
取决于要运行的ProGuard的日志输出. ProGuard是真正分析代码以了解未使用内容的人.
ProGuard shrinks CODE ONLY; shrinkResources
it's just the stuff from the /res/
folder. shrinkResources
depends on the log output from ProGuard to run. ProGuard is the one who actually analyses the code to know what is unused.
我刚刚找到了一篇非常不错的博客文章. CommonsWare将其发布在其他堆栈上最低问题: http://cyrilmottier.com/2014/08/26/putting-your-apks-on-diet/
I've just found a very nice blog post. CommonsWare posted it on some other stackOverlow question: http://cyrilmottier.com/2014/08/26/putting-your-apks-on-diet/
它完美地解释了您的后续问题:
it explains it perfectly your follow up question:
为什么一个要依赖另一个?
why would one depend on the other?
来自帖子:
Proguard在Java端工作.不幸的是,它在资源方面不起作用.因此,如果未使用res/drawable中的my_image图像,则Proguard只会在R类中删除其引用,而将相关的图像保留在适当的位置.
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.
这意味着,shrinkResources
仅在文件夹中有可绘制对象而不是R
类上时进行比较.
that means, that shrinkResources
only compares if a drawable is in the folder but not on the R
class.
这篇关于"minifyEnabled";与"shrinkResources" - 有什么不同?以及如何获得节省的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!