Proguard:如何不优化库中的类
我这里有一个 JavaME 项目,我必须在其中包含给定的库。我使用的是 Netbeans 6.8,所以我只是将库添加到项目中。然后将库的类正确打包到生成的 jar 文件中。
我现在的问题是这个库的类一定不能被 Proguard 混淆器触及。所以我尝试了不同的 -keep 选项:
-保留类 com.package.**
我也尝试过 -keepnames 和 -keepclassmembers,但 Proguard 将不再说:
编辑代码时出现意外错误:
类 = [com/package/class]
方法 = [run()V]
Exception = [java.lang.IllegalArgumentException](长度为 [1075] 的代码中的指令偏移量 [1077] 无效)
错误:长度为 [1075] 的代码中指令偏移量 [1077] 无效
有没有办法告诉 Proguard 忽略某个库或某些类?
提前致谢!
I've got a JavaME project here in which I had to include a given library. I'm using Netbeans 6.8, so I just added the library to the project. The classes of the library are then correctly packed into the resulting jar-file.
My problem now is that the classes of this library must not be touched by the Proguard obfuscator. So I've tried different -keep options:
-keep class com.package.**
I've also tried -keepnames and -keepclassmembers, but Proguard will quit saying:
Unexpected error while editing code:
Class = [com/package/class]
Method = [run()V]
Exception = [java.lang.IllegalArgumentException] (Invalid instruction offset [1077] in code with length [1075])
Error: Invalid instruction offset [1077] in code with length [1075]
Is there a way to tell Proguard to ignore a certain library or certain classes?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您希望 ProGuard 保持库不变,您应该使用 -libraryjars 而不是 -injars 指定它:
它的类不会包含在输出 jar 中,因此您仍然需要将库 jar 添加到您的类路径中已处理的申请。
或者,您可以将库 jar 作为输入 jar 进行处理,但保留其类和类成员:
现在,意外错误有所不同。它表明 ProGuard 中存在错误。您应该确保您使用的是最新版本的 ProGuard。否则,您应该在 Sourceforge 的 ProGuard 错误跟踪器上报告问题。
If you want ProGuard to leave a library untouched, you should specify it with -libraryjars instead of -injars:
Its classes won't be included in the output jar, so you then still have to add the library jar to the class path of your processed application.
Alternatively, you could process the library jar as an input jar, but keep its classes and class members:
Now, the unexpected error is something different. It indicates a bug in ProGuard. You should make sure you are using the latest version of ProGuard. Otherwise, you should report an issue on ProGuard's bug tracker at Sourceforge.
这就是你的问题所在。一旦它进入提供给 Proguard 的 jar 中,它将被处理。我相信您一定正在创建一个包含所有依赖项的大罐子。如果是这样,请将您的 JavaME 代码从这个大 jar 中排除,并将其保存在单独的 jar 中。那么 Proguard 将不会处理它。
否则,找到一种方法将 JavaMe 代码移动到单独的 jar 中,并使其成为您提供给 Proguard 的 jar 的依赖项。
That's where your issue is. Once it is in the jar provided to Proguard, it will be processed. I believe you must be creating a big jar with all dependencies. If so, exclude your JavaME code from this big jar and keep it in a separate jar. Then Proguard won't process it.
Else, find a way to move your JavaMe code in a separate jar and make it a dependency of the jar you are providing to Proguard.
您可以使用 ProGuard 将 JAR 组合在一个单独的通道中,并指定以下选项:
其具有组合 JAR 而不处理它们的简单效果。
dontnote
和dontwarn
选项用于抑制注释和警告,这对于简单的组合操作来说是虚假的(并且会有很多)。第一遍应如下所示:
第二遍应如下所示:
You can combine your JARs in a separate pass with ProGuard, specifying these options:
Which has the simple effect of combining JARs without processing them at all.
The
dontnote
anddontwarn
options are to suppress notes and warning, which for a simple combine operation are spurious (and there will be a number of them).The first pass should look something like:
The second pass should look like: