问题描述
我正在尝试在Android上使用一个使用 sun.misc.Unsafe
的Java库jar。对库的调用抛出一个
I'm trying to use a Java library jar on Android that uses sun.misc.Unsafe
. A call to the library throws a
java.lang.NoSuchMethodError:类Lsun中没有虚方法ensureClassInitialized(Ljava / lang / Class;)V /杂项/不安全的;或其超类('sun.misc.Unsafe'的声明出现在/system/framework/core-libart.jar中)
As据我所知, sun.misc.Unsafe
不是Android API的一部分。所以我试图在我的应用程序中手动包含 sun.misc.Unsafe
(从)。但是,仍然会抛出异常。
As far as I understood sun.misc.Unsafe
is not part of the Android API. So I tried to include the sun.misc.Unsafe
in my app manually (downloaded the file from here). However, the exception is still thrown.
任何想法,我如何在Android上使用库jar?
Any ideas, how I can use the library jar on Android?
推荐答案
有一个Android版本的 sun.misc.Unsafe
(参见),但它不包括该特定方法。 (我假设该方法是在Java 7中引入的......)
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 ...)
使用OpenJDK版本的不安全
on Dalvik / Android无法运行,因为它依赖于Dalvik VM未实现的本机方法。 (看起来你甚至没有设法让Davlik加载OpenJDK版本而不是Android版本。)
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.)
注意一些不安全的
方法可以在Android上使用...但只能使用我链接到的类的版本。
Note that some Unsafe
methods will be usable on Android... but only the ones in the version of the class I linked to.
这篇关于java.lang.NoSuchMethodError sun.misc.Unsafe与Android上的外部Jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!