Jersey Client supported with Android? - java

I want to use REST Jersey Client to invoke web services. But it is failing when invoked from android app; the same web service call works when invoked from simple java client (without any Android code). Does it mean Jersey Client doesn't work when invoked in Android's context or it needs any specific configuration to make a REST call?
My pom.xml has this:
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.13</version>
</dependency>
My sample code:
Response getResponse = ClientBuilder.newClient()
.target("http://myserver:8081").path("/users/employees")
.request()
.get();
I see these ERRORS in android emulator logs:
Failed resolving Lorg/glassfish/jersey/internal/OsgiRegistry; interface 2690 'Lorg/osgi/framework/SynchronousBundleListener;'
Link of class 'Lorg/glassfish/jersey/internal/OsgiRegistry;' failed
VFY: unable to find class referenced in signature (Lorg/glassfish/jersey/internal/OsgiRegistry;)
...
Cannot find default implementation of the HK2 ServiceLocatorGenerator
java.lang.ClassNotFoundException: Provider of org.glassfish.jersey.internal.RuntimeDelegateImpl could not be instantiated: java.lang.IllegalStateException: No generator was provided and there is no default generator registered.
Related comment here:
"Android has Dalvik Virtual Machine, not original JVM. I think this the reason why Jersey Client API does not work in Android OS. but I'am nog sure!"

This post is related:
When using Jersey for restful api in Android app I get this error:
It seems that the Jersey Client is not supported in android: I tried importing a working jersey Client for REST api program in android and got a fatal exception.
12-16 16:41:33.049 3711-3711/com.program.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.program.example, PID: 3711
java.lang.VerifyError: com/sun/jersey/core/impl/provider/entity/MimeMultipartProvider
at java.lang.Class.getDeclaredConstructors(Native Method)
at java.lang.Class.getConstructors(Class.java:508)
at com.sun.jersey.core.spi.component.ComponentConstructor.getInstance(ComponentConstructor.java:174)
at com.sun.jersey.core.spi.component.ProviderFactory.__getComponentProvider(ProviderFactory.java:166)
at com.sun.jersey.core.spi.component.ProviderFactory.getComponentProvider(ProviderFactory.java:137)
at com.sun.jersey.core.spi.component.ProviderServices.getComponent(ProviderServices.java:256)
at com.sun.jersey.core.spi.component.ProviderServices.getServices(ProviderServices.java:160)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:176)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
at com.sun.jersey.api.client.Client.init(Client.java:342)
at com.sun.jersey.api.client.Client.access$000(Client.java:118)
at com.sun.jersey.api.client.Client$1.f(Client.java:191)
at com.sun.jersey.api.client.Client$1.f(Client.java:187)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:187)
at com.sun.jersey.api.client.Client.<init>(Client.java:159)
at com.sun.jersey.api.client.Client.create(Client.java:669)
at android.view.View.performClick(View.java)
at android.view.View$PerformClick.run(View.java)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
at dalvik.system.NativeStart.main(Native Method)
I wish I could make it a comment...

Related

Attempt to invoke virtual method 'java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String)' on a null object reference

I updated my android studio from 3.1.2 to 3.1.3 and updated my project sdk version to 28 and when i run the application it crashes as soon as it open and throws the following exception,
FATAL EXCEPTION: main
Process: com.google.android.apps.nexuslauncher, PID: 10288
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String)' on a null object reference
at android.os.Parcel.createException(Parcel.java:1948)
at android.os.Parcel.readException(Parcel.java:1865)
at android.app.IActivityManager$Stub$Proxy.startActivity(IActivityManager.java:4541)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1660)
at android.app.Activity.startActivityForResult(Activity.java:4574)
at com.android.launcher3.Launcher.startActivityForResult(SourceFile:1394)
at android.app.Activity.startActivity(Activity.java:4889)
at com.android.launcher3.Launcher.startActivitySafely(SourceFile:2000)
at com.android.launcher3.Launcher.startAppShortcutOrInfoActivity(SourceFile:1850)
at com.android.launcher3.Launcher.onClick(SourceFile:1703)
at android.view.View.performClick(View.java:6579)
at android.view.View.performClickInternal(View.java:6556)
at android.view.View.access$3100(View.java:777)
at android.view.View$PerformClick.run(View.java:25660)
at android.os.Handler.handleCallback(Handler.java:819)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Caused by: android.os.RemoteException: Remote stack trace:
at android.app.LoadedApk.createAppFactory(LoadedApk.java:224)
at android.app.LoadedApk.<init>(LoadedApk.java:152)
at android.app.ActivityThread.getPackageInfo(ActivityThread.java:2043)
at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1998)
at android.app.ActivityThread.getPackageInfo(ActivityThread.java:1970)
It is a problem of API P emulator. On API 28, 27 it works right.
As CoolMind said, It is a problem in API P emulator, you can solve it by updating your Google APIs Intel System Image in Android SDK.
Add these two lines in your gradle.properties file and then build project. After i added these lines, Android Studio showed stacktrace in Logcat.I fixed those issues and then my app started working.
android.enableD8.desugaring = true
android.enableR8 = true

java.lang.NoClassDefFoundError: com.google.android.gms.common.internal.zzbo

I know this question may be duplicate but I have tried many solutions but I am unable to make my app work. It should be noted that I have enabled Multidex but still getting below error. I am creating a react native app.
FATAL EXCEPTION: main
Process: com.xxxxxx.yyyyyyyy, PID: 3978
java.lang.NoClassDefFoundError: com.google.android.gms.common.internal.zzbo
at com.google.firebase.provider.FirebaseInitProvider.attachInfo(Unknown Source)
at android.app.ActivityThread.installProvider(ActivityThread.java:5049)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:4623)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4563)
at android.app.ActivityThread.access$1500(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1402)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5333)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
If you are developing a react native application and above error came , just make sure that all of your dependencies's Gradle are using same version of firebase servces and play service base.
For example :- my app level gradle file contains
compile "com.google.android.gms:play-services-base:11.4.0"
compile "com.google.firebase:firebase-core:11.4.0"
compile "com.google.firebase:firebase-messaging:11.4.0"
compile "com.google.firebase:firebase-analytics:11.4.0"
compile "com.google.firebase:firebase-crash:11.4.0"
compile "com.google.firebase:firebase-ads:11.4.0"
and one react-native library is using
compile "com.google.android.gms:play-services-base:11.8.0"
and other one library is using
compile "com.google.android.gms:play-services-base:+"
so what i did , i changed all services version to 11.8.0.
BTW you can see gradles of all libraries or dependencies when you open your react-native-project/android folder in Android studio
I hope this will solve your issue

java.lang.NoClassDefFoundError: java.awt.Image in android

I am facing the following issue in Android.
FATAL EXCEPTION: main
Process: pkg.demo, PID: 22090
java.lang.NoClassDefFoundError: java.awt.Image
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.(RuntimeBuiltinLeafInfoImpl.java:372)
at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.(RuntimeTypeInfoSetImpl.java:65)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:133)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:85)
at com.sun.xml.bind.v2.model.impl.ModelBuilder.(ModelBuilder.java:156)
at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.(RuntimeModelBuilder.java:93)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:455)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:303)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.(JAXBContextImpl.java:142)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1174)
at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:162)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:202)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:363)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:574)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:522)
The cause of your problem is in the first line of the exception:
FATAL EXCEPTION: main Process: pkg.demo, PID: 22090 java.lang.NoClassDefFoundError: java.awt.Image at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.
Android cannot find the class java.awt.Image. This is because Image is an AWT class; AWT is a toolkit that does not exist in Android.
This error originates at com.sun.xml.bind.v2.modle.impl.RuntimeBuiltinLeafInfoImpl. So, it seems you've added a library that relies upon AWT.
The solution is to see if this library has been ported to Android; then use the Android port.
If there is no port, you'll have to find another library.

Error - Didn't find class "javax.naming.ldap.LdapName"

I'm using unirest to get a camfind result.
The full error log :
04-14 18:24:39.574 1880-2300/projectco.project E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-120
Process: projectco.project, PID: 1880
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/naming/ldap/LdapName;
at com.mashape.relocation.conn.ssl.AbstractVerifier.extractCNs(AbstractVerifier.java:277)
at com.mashape.relocation.conn.ssl.AbstractVerifier.getCNs(AbstractVerifier.java:265)
at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:157)
at com.mashape.relocation.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:140)
[...] more "at"s
at bookshotco.bookshot2.MainActivity$1.run(MainActivity.java:100)
at java.lang.Thread.run(Thread.java:818)
Caused by: java.lang.ClassNotFoundException: Didn't find class "javax.naming.ldap.LdapName" on path: DexPathList[[zip file "/data/app/projectco.project-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
[..]
Suppressed: java.lang.ClassNotFoundException: javax.naming.ldap.LdapName
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)
... 23 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
Few people had this problem and even fewer solved it, most of the times using stuff to do with compatibility of different versions which did not work for me.
The emulator I'm using is up to date (nexus 5 on api 21).
I've recently had the same issue and it was only happening in obfuscated code. So keeping the whole org.apache package in Proguard rules solved the issue.
# Keep Apache Package, since it cannot find some of the classes and throws Verify Error
-keep class org.apache.** {*;}
This error can also be caused by requiring ssl (i.e., "useSSL") when connecting to a remote server and NOT having verifyServerCertificate and trustServerCertificate defined as below, and also not having a server certificate defined properly. The system is trying to use an LDAP authentication process, thus the error.
val info = Properties()
info.setProperty("useSSL", "true")
info.setProperty("requireSSL", "true")
info.setProperty("user", user)
info.setProperty("password", password)
info.setProperty("verifyServerCertificate", "false")
info.setProperty("trustServerCertificate", "true")
Also, if you define:
trustServerCertificate=false
then you may need to set the following (unless everything matches up):
disableSslHostnameVerification=true

Android/Adobe air crash report: java.lang.UnsatisfiedLinkError

i am getting this error inside Google's "Crashes & ANRs". The application built with Adobe Air and packaged as captive runtime.
java.lang.UnsatisfiedLinkError: nativeSurfaceCreated
at com.adobe.air.AIRWindowSurfaceView.nativeSurfaceCreated(Native Method)
at com.adobe.air.AIRWindowSurfaceView.surfaceCreated(AIRWindowSurfaceView.java:719)
at android.view.SurfaceView.updateWindow(SurfaceView.java:545)
at android.view.SurfaceView.access$000(SurfaceView.java:81)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:693)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1731)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2583)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4508)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
at dalvik.system.NativeStart.main(Native Method)
Does anybody know what this means?
The UnsatisfiedLinkError for Java usually means that you tried to load a library called nativeSurfaceCreated. Basically your code called a method that called a method and so on, and some code somebody else wrote called a native method. This native method loaded a library called nativeSurfaceCreated, which you don't have. This is usually packaged in a dll in Windows or a so file in Linux. If you can find this dll/so file, you can probably run whatever you're running.

Categories