开发者

Android Link Error

开发者 https://www.devze.com 2023-01-27 07:45 出处:网络
I\'m running Ubuntu 10.10 I\'m NOT using the NDK I compiled my ARM shared library in DS-5 (ARM\'s development toolset, http://www.keil.com/arm/ds5/ ).When I placed them under libs/armeabi and call S

I'm running Ubuntu 10.10

I'm NOT using the NDK

I compiled my ARM shared library in DS-5 (ARM's development toolset, http://www.keil.com/arm/ds5/ ). When I placed them under libs/armeabi and call System.loadLibrary() it can't find them.

Here's the class:

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);

}

Th开发者_JAVA技巧e library's exact name is libAddSub.so

The 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)


First, you really should use the ndk rather than some other gcc build such as codesourcery, and especially rather than a non-gcc compiler which may not even produce object files in a compatible format.

Second, as an experiment try using system.load() instead which takes a full pathname. But still be prepared for problems if you aren't using the ndk gcc.

0

精彩评论

暂无评论...
验证码 换一张
取 消