cottonBallPaws
cottonBallPaws

Reputation: 21600

Proguard issues with jar files, how to find the missing jar?

When I try to export my apk with Proguard I get a lot of errors (over 400) similar to:

Warning: org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper: can't find superclass or interface javax.ws.rs.ext.ExceptionMapper

and

org.codehaus.jackson.xc.DataHandlerJsonDeserializer$1: can't find superclass or interface javax.activation.DataSource

I am using the Jackson Json library, and the errors seem related to that.

Researching this error I found the following from Proguards FAQ:

If there are unresolved references to classes or interfaces, you most likely forgot to specify an essential library. For proper processing, all libraries that are referenced by your code must be specified, including the Java run-time library. For specifying libraries, use the -libraryjars option.

Searching around on SO I found a lot of unanswered questions related to this, but the general sense was that the jar file I am using (in this case Jackon JSON) is relying on more libraries and they need to be added to Proguard's config file some how.

However, I can't figure out how to determine what jars are needed and where they are. The warnings mention a lot of different packages such as javax.ws.rs.ext, org.joda.time, org.codehaus.stax2, javax.xml.stream, etc.

  1. How do I determine what jars contain those packages? For example, what jar is required for the javax.ws.rs.ext.** classes?
  2. How do I figure out where those jars are and what path would be used with -libraryjars in Proguard?

Thanks much


Edit: I should also mention that I am using an Android Library Project setup. The jars are in the main Library project, and the actual working project has their build paths including the jars in the Library project. Don't know if that makes a difference but thought I should mention it.


Update Just to test, I completely removed the jackson far from the build path and from my code and now Proguard completes successfully. The questions still remain... What is the correct approach for handling these errors?

Does the Android export wizard in Eclipse automatically add the /lib/ jars to proguard or do they all have to be added manually in the proguard config file like this:

-libraryjars C:/Project/lib/somjar.jar

I did try that for the jackson one but it didn't make any difference. Does this mean I also have to find all of the jars that are needed for the classes mentioned in the warnings and add those? Would they be in the sdk or in the java installation?

Sorry if these are stupid questions, but I have been trying to figure this out for the last couple hours and have no idea what to do.

Thanks again


Update Again

So more searching, combined with Benjamin's suggestion, I found some of the missing classes were in rt.jar, which is in the jdk's lib folder. So I ended up adding

-libraryjars  <java.home>/lib/rt.jar

To the proguard.cfg file and brought the warnings from 485 down to 204. Hey I guess that's something... The remaining warnings describe classes that I cannot find at all. The app works just fine without running proguard, so these classes must be somewhere right? Or are these warnings that I should use -dontwarn with?

The remaining classes are in these packages:

org.joda.time.
org.codehaus.stax2.
javax.ws.rs.

So now I just need a way to figure out:

  1. What jars have these classes
  2. Where are these jars so I can include them in the proguard config file

Upvotes: 13

Views: 8381

Answers (3)

Benjamin Seiller
Benjamin Seiller

Reputation: 2905

I only can provide an answer for the first part: Give

http://www.findjar.com

a try, there you might find the names of the needed jar files like so

Upvotes: 3

Paul Lammertsma
Paul Lammertsma

Reputation: 38252

You don't need to include the libraries for Proguard; you need to instead instruct Proguard to keep the class names and some other stuff. I toyed around with it a bit myself, and I ended up with something similar to this discussion:

-keepnames class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**

If you're still experiencing crashes—and I would suggest testing vigorously!—you might want to keep Jackson completely intact with:

-keep class org.codehaus.** { *; }
-keepattributes *Annotation*,EnclosingMethod
-dontwarn org.codehaus.jackson.**

(Note that the latter produces a larger file.)

Upvotes: 0

NickT
NickT

Reputation: 23873

I've had similar problems with Proguard and similar errors I was using an osmdroid.jar which built OK unobfuscated. This jar must have had external dependencies which my application didn't need. Fortunately the authors listed the jars needed and once I downloaded them and told Proguard via the -libraryjars option, the Proguard build was OK.

Re your missing jars (which you probably don't really need, but Proguard thinks you might!), you should find them at:

org.joda.time (The jar's inside the zip)

org.codehaus.stax2.

javax.ws.rs.

Upvotes: 5

Related Questions