Proguard:如何不优化库中的类

发布于 2024-09-08 18:57:18 字数 545 浏览 6 评论 0原文

我这里有一个 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 技术交流群。

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

发布评论

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

评论(3

不一样的天空 2024-09-15 18:57:19

如果您希望 ProGuard 保持库不变,您应该使用 -libraryjars 而不是 -injars 指定它:

-libraryjars somelibrary.jar

它的类不会包含在输出 jar 中,因此您仍然需要将库 jar 添加到您的类路径中已处理的申请。

或者,您可以将库 jar 作为输入 jar 进行处理,但保留其类和类成员:

-keep class some.library.** { *; }

现在,意外错误有所不同。它表明 ProGuard 中存在错误。您应该确保您使用的是最新版本的 ProGuard。否则,您应该在 Sourceforge 的 ProGuard 错误跟踪器上报告问题。

If you want ProGuard to leave a library untouched, you should specify it with -libraryjars instead of -injars:

-libraryjars somelibrary.jar

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:

-keep class some.library.** { *; }

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.

掩饰不了的爱 2024-09-15 18:57:19

然后将库的类正确打包到
生成的 jar 文件。

这就是你的问题所在。一旦它进入提供给 Proguard 的 jar 中,它将被处理。我相信您一定正在创建一个包含所有依赖项的大罐子。如果是这样,请将您的 JavaME 代码从这个大 jar 中排除,并将其保存在单独的 jar 中。那么 Proguard 将不会处理它。

否则,找到一种方法将 JavaMe 代码移动到单独的 jar 中,并使其成为您提供给 Proguard 的 jar 的依赖项。

The classes of the library are then correctly packed into the
resulting jar-file.

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.

一个人练习一个人 2024-09-15 18:57:19

您可以使用 ProGuard 将 JAR 组合在一个单独的通道中,并指定以下选项:

-dontnote **
-dontwarn **
-dontobfuscate
-dontshrink
-dontoptimize

其具有组合 JAR 而不处理它们的简单效果。

dontnotedontwarn 选项用于抑制注释和警告,这对于简单的组合操作来说是虚假的(并且会有很多)。

第一遍应如下所示:

-injars        MyApplication-Unobfuscated.jar
-libraryjars   SomeLibraryJar.jar(!META-INF/**)
-libraryjars   AnotherLibraryJar.jar(!META-INF/**)
-outjars       MyApplication-Obfuscated.jar

// other options.

第二遍应如下所示:

-injars        MyApplication-Obfuscated.jar
-injars        SomeLibraryJar.jar(!META-INF/**)
-injars        AnotherLibraryJar.jar(!META-INF/**)
-outjars       MyApplication.jar

-dontnote **
-dontwarn **
-dontobfuscate
-dontshrink
-dontoptimize

You can combine your JARs in a separate pass with ProGuard, specifying these options:

-dontnote **
-dontwarn **
-dontobfuscate
-dontshrink
-dontoptimize

Which has the simple effect of combining JARs without processing them at all.

The dontnote and dontwarn 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:

-injars        MyApplication-Unobfuscated.jar
-libraryjars   SomeLibraryJar.jar(!META-INF/**)
-libraryjars   AnotherLibraryJar.jar(!META-INF/**)
-outjars       MyApplication-Obfuscated.jar

// other options.

The second pass should look like:

-injars        MyApplication-Obfuscated.jar
-injars        SomeLibraryJar.jar(!META-INF/**)
-injars        AnotherLibraryJar.jar(!META-INF/**)
-outjars       MyApplication.jar

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