X
  • REST |
    January 30, 2015

Jersey 2.x Client on Android

From time to time, people are asking for Jersey Client support on Android device. Until Jersey version 2.15 it was not possible to get Jersey client running on Android devices due to javax.xml.stream dependencies included directly in the Jersey client core module. A list of Android supported Java packages is available here and the javax.xml.stream package is missing there.

Current Jersey snapshot version introduces a new JAX-B module, so that all JAXB-B Jersey client dependencies could have been separated out.
To prove things work better now for Jersey Client on Android, i have put together a simple mobile application to see what happens (project zip archive available for download).

The Blocker

To reproduce the issue, i wrote a simple application consisting of just a single entry field for an URL, and then a big text view
where i display content retrieved from the given URL using Jersey Client 2.15. The application looks like this:

I run the application in an Android emulator. Now after entering an URL and clicking the FETCH button here is what i got:

    Suppressed: java.lang.ClassNotFoundException: javax.xml.stream.XMLInputFactory
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 35 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

Here is a snapshot from the Android Studio:

Not to mention, the mobile application crashed...

The original issue has been removed, things work now, but...


After upgrading Jersey dependency in my Android application to version 2.16-SNAPSHOT, i was able to retrieve some data via my Jersey Client finally:

Great news, but when i checked the error log, i have seen this:

[org.glassfish.jersey.message.internal.DataSourceProvider] with an exception:
MultiException stack 1 of 4
java.lang.NoClassDefFoundError: javax.activation.DataSource
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:479)
at java.lang.reflect.ArtMethod.getDexCacheType(ArtMethod.java:229)
at java.lang.reflect.ArtMethod.getReturnType(ArtMethod.java:178)
at java.lang.reflect.Method.getReturnType(Method.java:184)
at java.lang.Class.getDeclaredMethods(Class.java:771)
at org.glassfish.hk2.utilities.reflection.internal.ClassReflectionHelperImpl$3.run(ClassReflectionHelperImpl.java:119)
at org.glassfish.hk2.utilities.reflection.internal.ClassReflectionHelperImpl$3.run(ClassReflectionHelperImpl.java:115)
at java.security.AccessController.doPrivileged(AccessController.java:45)
...

Hmm, another issue, not a real blocker (no application crash this time), but still quite annoying.

What next?

Apparently, we need to get rid of the other exception.

Additionally, to make sure Jersey Client is usable on Android, i would like to have some more advanced scenario tested (JSON support e.g.) as well.
Since this was my very first experience with Android development, any suggestions in this area are more than welcome. Otherwise i can only guess what kind of support people are expecting to have.

Summary


From Jersey version 2.16, it should be possible to use Jersey Client on Android. The support is still not perfect, but i hope we will be able to resolve the last obstacles soon. Hopefully with some help from the community.

Join the discussion

Comments ( 4 )
  • Jakub Podlešák Friday, January 30, 2015

    My colleague just told me the unzipped project could not be opened due to some broken references. I will try to fix that early next week.


  • Harish Ravichandran Friday, February 13, 2015

    In my case, the second issue (java.lang.NoClassDefFoundError: javax.activation.DataSource) does cause the application to crash. So it would seem that version 2.16 is still not usable on Android.

    Is there a timeline to have it working completely on Android?

    Thanks.


  • Jakub Podlešák Monday, March 2, 2015

    Hi Harish, I am sorry to hear that. There is no timeline. Would you mind sharing some more details on your use-case? On my side, the application crash sometimes, but it is dependent on what URI i am trying to fetch rather than the client code itself.


  • guest Tuesday, March 17, 2015

    @Harish: Please check out the following workaround and let me know if it works for you. Thanks! https://blogs.oracle.com/japod/entry/jersey_2_x_client_on1


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services