jeff_bordon jeff_bordon -5 years ago 393
Android Question

java.lang.NoSuchMethodError sun.misc.Unsafe with external Jar on Android

I'm trying to use a Java library jar on Android that uses

. A call to the library throws a

java.lang.NoSuchMethodError: No virtual method ensureClassInitialized(Ljava/lang/Class;)V in class Lsun/misc/Unsafe; or its super classes (declaration of 'sun.misc.Unsafe' appears in /system/framework/core-libart.jar)

As far as I understood
is not part of the Android API. So I tried to include the
in my app manually (downloaded the file from here). However, the exception is still thrown.

Any ideas, how I can use the library jar on Android?

Answer Source

Any ideas, how I can use the library jar on Android?

There is a Android version of sun.misc.Unsafe (see here), but it doesn't include that particular method. (I assume that the method was introduced in Java 7 ...)

Using the OpenJDK version of Unsafe on Dalvik / Android won't work, because it depends on native methods that are not implemented by the Dalvik VM. (And it looks like you didn't even manage to get Davlik to load the OpenJDK version instead of the Android version.)

Note that some Unsafe methods will be usable on Android... but only the ones in the version of the class I linked to.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download