Android 上的 Proguard 坏了?

发布于 2024-12-16 12:50:28 字数 1276 浏览 0 评论 0原文

我曾经能够按照这里的指南< /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-12-23 12:50:28

Proguard 最小化应用程序大多不能开箱即用。在大多数情况下,您必须手动指定需要保留的其他类。

在您的情况下,我将首先添加配置行

-keep class com.mysoftware.informaltimeprovider.InformalTimeProvider

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

-keep class com.mysoftware.informaltimeprovider.InformalTimeProvider

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文