eclipse 如何判断 Proguard 是否已完成其工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10190907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to tell if Proguard has done its job
提问by Mick
I downloaded proguard encapsulated in a zip file and unpacked it onto my hard disk. I did not installit in any way (because I didn't know how). I then added proguard.config=proguard.cfgto my project.properties file. I then did an "export android application" fully expecting eclipse to complain that it didn't know where my proguard installation was, but there was no complaint. Indeed a new apk file appeared in my keystore, and a set of files (dump.txt etc) appeared in my app's proguard subdirectory. The mapping.txt looks like a nice list of mappings from my long variable names to one and two letter variables. This should all be strong evidence that proguard has somehow worked - my only concern is that the apk is scarcely any smaller than it was before. Is there any way to check that the apk includes proguard's obfuscations?
我下载了封装在 zip 文件中的 proguard 并将其解压到我的硬盘上。我没有以任何方式安装它(因为我不知道如何安装)。然后我添加proguard.config=proguard.cfg到我的 project.properties 文件中。然后我做了一个“导出 android 应用程序”,完全期待 eclipse 抱怨它不知道我的 proguard 安装在哪里,但没有抱怨。实际上,我的密钥库中出现了一个新的 apk 文件,我的应用程序的 proguard 子目录中出现了一组文件(dump.txt 等)。mapping.txt 看起来像是一个很好的映射列表,从我的长变量名到一个和两个字母的变量。这应该都是 proguard 以某种方式起作用的有力证据 - 我唯一担心的是 apk 几乎没有比以前小了。有什么方法可以检查apk是否包含proguard'
回答by Kuffs
回答by vaughandroid
An alternative to @Kuffs method would be to compare your new APK with an old one. Open them both up (with 7zip or your preferred tool) and compare the size of the classes.dex files in each of them.
@Kuffs 方法的替代方法是将您的新 APK 与旧 APK 进行比较。打开它们(使用 7zip 或您喜欢的工具)并比较每个文件中 classes.dex 文件的大小。
A few straightforward reasons you might not be seeing much of a size saving:
您可能看不到节省多少尺寸的一些直接原因:
- The unobfuscated classes.dex was able to be compressed much more than the obfuscated one. This is always true to some extent.
- You didn't do a release build. Proguard only gets run on release builds since debugging obfuscated code is a nightmare.
- The Proguard settings you're using aren't doing much good (at least in terms of code size) for your project. I've actually seen proguard's code inlining settings increase the size of jar files before!
- 未混淆的 classes.dex 能够比混淆的更压缩。这在某种程度上总是正确的。
- 您没有进行发布版本。Proguard 只在发布版本上运行,因为调试混淆代码是一场噩梦。
- 您使用的 Proguard 设置对您的项目没有多大好处(至少在代码大小方面)。实际上,我之前已经看到 proguard 的代码内联设置增加了 jar 文件的大小!

