1

我已将 jnix.jar 文件放在 libs 文件夹中并添加到构建路径中。但是当我尝试使用 System.loadLibrary("jnix") 加载库时,我收到以下崩溃。它虽然列在引用的库中。

03-07 22:04:24.822: E/streamer(8746): Couldn't load jnix: findLibrary returned null
03-07 22:04:24.822: E/streamer(8746): java.lang.UnsatisfiedLinkError: Couldn't load jnix: findLibrary returned null
03-07 22:04:24.822: E/streamer(8746):   at java.lang.Runtime.loadLibrary(Runtime.java:365)
03-07 22:04:24.822: E/streamer(8746):   at java.lang.System.loadLibrary(System.java:535)
03-07 22:04:24.822: E/streamer(8746):   at ob.android.MainActivity.<clinit>(MainActivity.java:38)
03-07 22:04:24.822: E/streamer(8746):   at java.lang.Class.newInstanceImpl(Native Method)
03-07 22:04:24.822: E/streamer(8746):   at java.lang.Class.newInstance(Class.java:1319)
03-07 22:04:24.822: E/streamer(8746):   at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
03-07 22:04:24.822: E/streamer(8746):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
03-07 22:04:24.822: E/streamer(8746):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
03-07 22:04:24.822: E/streamer(8746):   at android.app.ActivityThread.access$600(ActivityThread.java:139)
03-07 22:04:24.822: E/streamer(8746):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
03-07 22:04:24.822: E/streamer(8746):   at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 22:04:24.822: E/streamer(8746):   at android.os.Looper.loop(Looper.java:154)
03-07 22:04:24.822: E/streamer(8746):   at android.app.ActivityThread.main(ActivityThread.java:4945)
03-07 22:04:24.822: E/streamer(8746):   at java.lang.reflect.Method.invokeNative(Native Method)
03-07 22:04:24.822: E/streamer(8746):   at java.lang.reflect.Method.invoke(Method.java:511)
03-07 22:04:24.822: E/streamer(8746):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-07 22:04:24.822: E/streamer(8746):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-07 22:04:24.822: E/streamer(8746):   at dalvik.system.NativeStart.main(Native Method)
03-07 22:04:24.822: W/dalvikvm(8746): Exception Ljava/lang/RuntimeException; thrown while initializing Lob/android/MainActivity;
03-07 22:04:24.822: W/dalvikvm(8746): Class init failed in newInstance call (Lob/android/MainActivity;)
03-07 22:04:24.822: D/AndroidRuntime(8746): Shutting down VM
03-07 22:04:24.822: W/dalvikvm(8746): threadid=1: thread exiting with uncaught exception (group=0x40abe228)
03-07 22:04:24.862: E/AndroidRuntime(8746): FATAL EXCEPTION: main
03-07 22:04:24.862: E/AndroidRuntime(8746): java.lang.ExceptionInInitializerError
03-07 22:04:24.862: E/AndroidRuntime(8746):     at java.lang.Class.newInstanceImpl(Native Method)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at java.lang.Class.newInstance(Class.java:1319)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.app.Instrumentation.newActivity(Instrumentation.java:1039)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2101)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.app.ActivityThread.access$600(ActivityThread.java:139)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.os.Looper.loop(Looper.java:154)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at android.app.ActivityThread.main(ActivityThread.java:4945)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at java.lang.reflect.Method.invokeNative(Native Method)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at java.lang.reflect.Method.invoke(Method.java:511)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at dalvik.system.NativeStart.main(Native Method)
03-07 22:04:24.862: E/AndroidRuntime(8746): Caused by: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Couldn't load jnix: findLibrary returned null
03-07 22:04:24.862: E/AndroidRuntime(8746):     at ob.android.MainActivity.<clinit>(MainActivity.java:47)
03-07 22:04:24.862: E/AndroidRuntime(8746):     ... 15 more
03-07 22:04:24.862: E/AndroidRuntime(8746): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load jnix: findLibrary returned null
03-07 22:04:24.862: E/AndroidRuntime(8746):     at java.lang.Runtime.loadLibrary(Runtime.java:365)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at java.lang.System.loadLibrary(System.java:535)
03-07 22:04:24.862: E/AndroidRuntime(8746):     at ob.android.MainActivity.<clinit>(MainActivity.java:38)
03-07 22:04:24.862: E/AndroidRuntime(8746):     ... 15 more
4

2 回答 2

0

loadLibrary() 用于本机代码,通常编译为 C 或 C++。Jar 是一个 Java 库,您可以在 Android 中使用此类库,但这些库将被编译到您的 Java 代码中。请注意,Android 运行不同的 JVM,其运行时环境仅与 JRE 部分兼容。

于 2013-03-07T19:27:39.363 回答
0

如上所述, System.loadLibrary() 用于本机代码。如果您的 jar 文件已正确添加到构建路径中,您应该能够像往常一样导入类。

例如,如果您要从 jar 文件中使用的类在 com.jnixpackage 包中,并且类名为 JnixClass,则可以通过添加来导入它

import com.jnixpackage.JnixClass;

到你的java文件的顶部。

于 2013-03-07T19:48:17.817 回答