我正在运行Ubuntu 10.10
我没有使用NDK
我在DS-5(ARM的开发工具集http://www.keil.com/arm/ds5/)中编译了我的ARM共享库。当我把它们放在libs / armeabi下并调用System.loadLibrary()时,它找不到它们。
这是班级:
package org.me.testds5;
//a JNI wrapper class
public class WrapMyNative
{
static
{
//ERROR HERE
//note that calling
//System.loadLibrary("libAddSub"); generates the same error
System.loadLibrary("AddSub");
}
//some native functions
public native int add(int a, int b);
public native int sub(int n, int m);
}
图书馆的确切名称是libAddSub.so
LogCat:
11-30 04:54:11.273: ERROR/AndroidRuntime(372): FATAL EXCEPTION: main
11-30 04:54:11.273: ERROR/AndroidRuntime(372): java.lang.ExceptionInInitializerError
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at org.me.testds5.TestDS5.onCreate(TestDS5.java:13)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.os.Looper.loop(Looper.java:123)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at java.lang.reflect.Method.invokeNative(Native Method)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at java.lang.reflect.Method.invoke(Method.java:521)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at dalvik.system.NativeStart.main(Native Method)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): Caused by: java.lang.UnsatisfiedLinkError: Library AddSub not found
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at java.lang.Runtime.loadLibrary(Runtime.java:461)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at java.lang.System.loadLibrary(System.java:557)
11-30 04:54:11.273: ERROR/AndroidRuntime(372): at org.me.testds5.WrapMyNative.<clinit>(WrapMyNative.java:7)
答案 0 :(得分:1)
首先,你真的应该使用ndk而不是其他一些gcc构建,例如codesourcery,尤其是非gcc编译器,它甚至可能不会以兼容格式生成目标文件。
其次,作为一个实验尝试使用system.load()而不是一个完整的路径名。但如果你没有使用ndk gcc,仍然可以为问题做好准备。