3

I have an Android project targeting API 17 which needs to consume a Jersey 2.4.1 REST service. However, at runtime I keep getting a NoClassDefFoundError for org.glassfish.jersey.model.internal.CommonConfig$1. This class is in the Jersey JAR files I need for the client code.

I have followed instructions from other posts about the libs Android dependency fix e.g. Android java.lang.NoClassDefFoundError but I still get the issue. The JAR is in the libs dir and I have checked the export option in the build path. What's weird is I have other jersey jars in this lib which are working, it just doesn't seem to find this one.

I have tried cleaning the project, refreshing it, removing and re-adding the JAR but I just can't seem to get it working. The class it complains about is in the jersey-common-2.4.1.jar which I can see in the Eclipse workspace so the right JAR is there, just seems it's not being exported with the APK.

UPDATE

I tried configuring ProGuard to see what gets produced but it was a never ending rabbit hole of warnings about classes and methods. In the end I just put -ignorewarnings in to get something output.

UPDATE2

I looked at the error message a little closer and it's actually missing org.glassfish.jersey.model.internal.CommonConfig$1 (note the $1). This is a static inner class which makes me almost certain that it's a ProGuard config issue. I tried adding:

-keepclasseswithmembers class org.glassfish.jersey.**
-keepclasseswithmembers class javax.ws.rs.**

to my proguard-project.txt file but I still get the NoClassDefFoundError. How can I tell Eclipse/ProGuard to leave my library jars alone completely for both kinds of build options (right click deploy and export)?

ANSWER/RESOLUTION

See my comment in response to @pjco.

Community
  • 1
  • 1
rossco
  • 523
  • 4
  • 20
  • Have you taken a peek inside your apk to see which classes are included? Is Progard enabled, and if so, configured correctly? – 323go Dec 08 '13 at 04:55
  • I am getting this using the standard debug deployment from Eclipse i.e. RightClick > Run As... > Android Application. I tried using Export to APK and turned on ProGuard but now I am getting a heap load of Warnings. I think its going to take quite a while to figure out all this ProGuard stuff, surely I don't need this to do a simple deployment to the device (non release build)? – rossco Dec 08 '13 at 22:26
  • No you don't need proguard -- I asked because if you had it enabled, you could have easily seen the sort of thing you're seeing. So, look inside your APK to see what's missing. – 323go Dec 08 '13 at 23:37
  • Sorry @323go, I'm not really sure what I should be looking for (or not in this case). If I unpack the APK it looks like its packaged like a JAR. Following the directory structure I do see that there is no path for org/glassfish/jersey/model/internal. Other package paths exist for JARs in the Android Dependencies lib and they have a localization.properies and sometimes a build.properties in the directory. I guess this is the problem but how to fix? – rossco Dec 09 '13 at 00:13

1 Answers1

0

Proguard isn't run by default. The $1 methods are generated by the compiler when an inner class tries to access something in the outer instance. Methods with a dollar sign and number are not Proguard related. Proguard names methods with letters (a,b,c, etc).

The libs folder should be exported by default. You should not need to configure the build path on recent versions of ADT (23).

Be sure to update ADT / build tools. Try starting a new project with the wizard in eclipse and place the jar in your libs folder. Then call some function in your jar from your MainActivity.

Do NOT change anything on the Java build path or any other similar settings

pjco
  • 3,826
  • 25
  • 25
  • 1
    I updated my all my Android tools and SDK and tried again but no luck. In the end I decided to add all jars I could find in another java client project I have which uses it successfully, and now it finds the class. The problem is dependencies, Jersey 2.4.1 requires not only a whole bunch of other jars but it also relies on classes from the JRE rt.jar e.g. (javax.xml.stream.*). I read somewhere that it's not good to use dependencies from there, so for this reason I think **I will scrap using Jersey as a client in Android**. Annoyed at all the wasted effort, now looking RESTDroid or Robospice – rossco Dec 15 '13 at 22:33
  • @rossco, which one did you end up using RESTDroid or Robospice? – th1rdey3 Dec 27 '13 at 08:09
  • 1
    Eventually implemented Robospice with the Retrofit library built in. It's pretty awesome, definitely recommend it if you are looking at consuming REST from Android. – rossco Dec 27 '13 at 12:54