Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 794
cottonBallPaws Avatar asked Feb 09 '11 20:02

cottonBallPaws


People also ask

How do I find a .JAR file?

We recommend using either 7-Zip or WinRAR. Once you have installed this software, run the software, open the jar file, and extract the files contained in it. Once the files are extracted, you can view the individual files by double clicking them.

Where is JAR located in Linux?

IF you are using the packing system, then a good choice is indeed /usr/share/java/ or /usr/lib (if your app is called from /usr/bin or /usr/sbin). Another good choice would be inside /usr/local, only if this app of yours is host specific.

What is the difference between JAR and library?

A JAR serves the same function an an Assembly in the C#/. net world. It's a collection of java classes, a manifest, and optionally other resources, such as properties files. A library is a more abstract concept, in java, a library is usually packaged as a JAR (Java ARchive), or a collection of JARs.


2 Answers

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.

like image 141
NickT Avatar answered Oct 25 '22 01:10

NickT


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

like image 30
Benjamin Seiller Avatar answered Oct 25 '22 00:10

Benjamin Seiller