Android 上的 Proguard 坏了?
我曾经能够按照这里的指南< /a> 作为构建的一部分来设置和运行 Proguard,没有任何问题。但是,自从更新到最新版本的 ADT 工具后,我遇到了麻烦。我遇到的第一个问题是:
BUILD FAILED
/home/myhome/projects/myapp/add-proguard-release.xml:14:
/home/myhome/projects/myapp/${out.classes.dir} does not exist.
所以我最终不得不在 local.properties 或 project.properties 中手动定义 ${out.classes.dir} 。不是世界末日,而是有点痛苦。
第二个更严重的问题与外部 jar 有关。我在外部罐子里有一个小班。当应用程序在设备上启动时,应用程序崩溃:
11-15 18:35:30.090: E/AndroidRuntime(28258): java.lang.NoClassDefFoundError: com.mysoftware.informaltimeprovider.InformalTimeProvider
11-15 18:35:30.090: E/AndroidRuntime(28258): at com.mysoftware.pagemonitor.PrintableTimeProvider.getInformalTime(PrintableTimeProvider.java:14)
尝试创建 InformalTimeProvider 实例时崩溃,但从 logcat 输出判断,此类没有被混淆,所以我不知道为什么会出现问题。
构建期间有一个警告:
[proguard] Copying resources from program jar [/home/myhome/projects/pagemonitor/libs/InformalTimeProvider.jar]
[proguard] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [InformalTimeProvider.jar:META-INF/MANIFEST.MF])
但这只是一个警告 - 我不希望发生崩溃。
非常感谢任何帮助。
巴里
I used to be able to follow the guide here to set up and run Proguard as part of a build, without any problems. However, since updating to the latest version of the ADT tools, I am having trouble. The first problem I run into is:
BUILD FAILED
/home/myhome/projects/myapp/add-proguard-release.xml:14:
/home/myhome/projects/myapp/${out.classes.dir} does not exist.
So I end up having to define ${out.classes.dir} manually in either local.properties or project.properties. Not the end of the world, but a bit of a pain.
The second, more drastic problem is related to external jars. I have a small class in an external jar. When the application launches on a device, the app crashes:
11-15 18:35:30.090: E/AndroidRuntime(28258): java.lang.NoClassDefFoundError: com.mysoftware.informaltimeprovider.InformalTimeProvider
11-15 18:35:30.090: E/AndroidRuntime(28258): at com.mysoftware.pagemonitor.PrintableTimeProvider.getInformalTime(PrintableTimeProvider.java:14)
It is crashing when trying to create an instance of InformalTimeProvider, but judging by the logcat output, this class was not obfuscated, so I don't know why there is a problem.
There is a warning during the build:
[proguard] Copying resources from program jar [/home/myhome/projects/pagemonitor/libs/InformalTimeProvider.jar]
[proguard] Warning: can't write resource [META-INF/MANIFEST.MF] (Duplicate zip entry [InformalTimeProvider.jar:META-INF/MANIFEST.MF])
It is just a warning though - I wouldn't expect a crash.
Any help gratefully received.
Barry
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Proguard 最小化应用程序大多不能开箱即用。在大多数情况下,您必须手动指定需要保留的其他类。
在您的情况下,我将首先添加配置行
This 明确告诉 proguard 该类是必需的且无法删除。如果之后你的应用程序错过了另一个类,请告诉 proguard 也保留它。
一步一步地,您将更接近一个完全运行的应用程序。我知道这种试错方法并不好,但优化 Java 应用程序并不那么简单,可以完全自动化。特别是通过字符串加载类和其他与运行时相关的技巧会与 proguard 发生冲突。
Proguard minimized apps mostly do not work out-of-the-box. In most cases you have to manually specify additional classes that needs to be kept.
In your case I would start by adding the configuration line
This explicitly tells proguard that this class is required and can not be removed. If afterwards your app misses another class tell proguard to keep it, too.
Step-by-step you will get closer to a fully working app. I know this try-and-error approach is not nice but optimizing Java Apps is not that simple that it can be fully automated. Especially loading classes by Strings and other run-time related tricks collide with proguard.