简体   繁体   English

Proguard:如何不优化库中的类

[英]Proguard: How not to optimize classes from a library

I've got a JavaME project here in which I had to include a given library. 我这里有一个JavaME项目,其中必须包含一个给定的库。 I'm using Netbeans 6.8, so I just added the library to the project. 我正在使用Netbeans 6.8,因此我只是将库添加到了项目中。 The classes of the library are then correctly packed into the resulting jar-file. 然后,将库的类正确打包到生成的jar文件中。

My problem now is that the classes of this library must not be touched by the Proguard obfuscator. 我现在的问题是Proguard混淆器一定不能触碰该库的类。 So I've tried different -keep options: 所以我尝试了不同的-keep选项:

-keep class com.package.** -保持类com.package。**

I've also tried -keepnames and -keepclassmembers, but Proguard will quit saying: 我也尝试过-keepnames和-keepclassmembers,但是Proguard会退出说:

Unexpected error while editing code: 编辑代码时发生意外错误:

Class = [com/package/class] 类别= [com / package / class]

Method = [run()V] 方法= [run()V]

Exception = [java.lang.IllegalArgumentException] (Invalid instruction offset [1077] in code with length [1075]) 异常= [java.lang.IllegalArgumentException](长度为[1075]的代码中的无效指令偏移[1077])

Error: Invalid instruction offset [1077] in code with length [1075] 错误:代码长度为[1075]的无效指令偏移[1077]

Is there a way to tell Proguard to ignore a certain library or certain classes? 有没有办法告诉Proguard忽略某些库或某些类?

Thanks in advance! 提前致谢!

If you want ProGuard to leave a library untouched, you should specify it with -libraryjars instead of -injars: 如果要让ProGuard保持库不变,则应使用-libraryjars而不是-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. 它的类不会包含在输出jar中,因此您仍然必须将库jar添加到已处理应用程序的类路径中。

Alternatively, you could process the library jar as an input jar, but keep its classes and class members : 另外,您可以将库jar处理为输入jar,但保留其类和类成员

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

Now, the unexpected error is something different. 现在,意外错误有所不同。 It indicates a bug in ProGuard. 它指示ProGuard中的错误。 You should make sure you are using the latest version of ProGuard. 您应该确保使用的是最新版本的ProGuard。 Otherwise, you should report an issue on ProGuard's bug tracker at Sourceforge. 否则,您应该在Sourceforge的ProGuard错误跟踪器上报告问题。

You can combine your JARs in a separate pass with ProGuard, specifying these options: 您可以使用ProGuard在单独的过程中结合使用JAR,并指定以下选项:

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

Which has the simple effect of combining JARs without processing them at all. 这具有合并JAR而不处理它们的简单效果。

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). dontnotedontwarn选项用于禁止显示注释和警告,对于简单的合并操作而言,它们是虚假的(并且会有很多)。

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

The classes of the library are then correctly packed into the resulting jar-file. 然后,将库的类正确打包到生成的jar文件中。

That's where your issue is. 那就是你的问题所在。 Once it is in the jar provided to Proguard, it will be processed. 将其放入Proguard提供的罐子中后,将对其进行处理。 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. 如果是这样,请从这个大罐子中排除JavaME代码,并将其保存在单独的罐子中。 Then Proguard won't process it. 然后Proguard将不会对其进行处理。

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. 否则,找到一种方法将JavaMe代码移动到单独的jar中,并使它成为您提供给Proguard的jar的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM