2

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!

3 Answers 3

1

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.

1
  • It's quite a common requirement to want build a distribution JAR that includes all dependencies but only has the application parts processed by ProGuard; maybe you could add a new option like inlibraryjars to enable this (and see my answer since combining without processing at all still spits out warnings if done as a second pass). Feb 2, 2014 at 0:23
0

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.

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.