java找不到.so文件,UnsatisfiedLinkError:找不到正确放置在Eclipse库中的.so文件的本机方法...

在尝试使用Android的本地方法时遇到了`UnsatisfiedLinkError`,问题指出找不到`MimasJNI.MIMAS_LoadModel`的本地方法。已确认armeabi,armeabi-v7a,mips和x86的库文件放置正确。加载`.so`文件的代码没有问题,但错误可能源于函数命名不匹配或未正确导出。解决方案包括检查库函数名称是否符合Java Native Interface (JNI) 的命名约定,并确保C++代码中函数有`extern C`前缀以避免名称修饰。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm new in using native methods for Android. I got the errors as below even after I have make sure my armeabi, armeabi-v7a, mips and x86 with correct *.so file are put correctly in the folders.

10-21 18:51:36.685: E/AndroidRuntime(24277): java.lang.UnsatisfiedLinkError: Native method not found: com.arzap.mimas.MimasJNI.MIMAS_LoadModel:(Ljava/lang/String;)V

10-21 18:51:36.685: E/AndroidRuntime(24277): at com.arzap.mimas.MimasJNI.MIMAS_LoadModel(Native Method)

10-21 18:51:36.685: E/AndroidRuntime(24277): at com.arzap.mimas.ar.MainActivity.onCreate(MainActivity.java:36)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.Activity.performCreate(Activity.java:5451)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.access$900(ActivityThread.java:175)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.os.Handler.dispatchMessage(Handler.java:102)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.os.Looper.loop(Looper.java:146)

10-21 18:51:36.685: E/AndroidRuntime(24277): at android.app.ActivityThread.main(ActivityThread.java:5602)

10-21 18:51:36.685: E/AndroidRuntime(24277): at java.lang.reflect.Method.invokeNative(Native Method)

10-21 18:51:36.685: E/AndroidRuntime(24277): at java.lang.reflect.Method.invoke(Method.java:515)

10-21 18:51:36.685: E/AndroidRuntime(24277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)

10-21 18:51:36.685: E/AndroidRuntime(24277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)

10-21 18:51:36.685: E/AndroidRuntime(24277): at dalvik.system.NativeStart.main(Native Method)

As below is how I loaded my .so file:

static{

try {

System.loadLibrary("libMimasAr3D");

} catch (UnsatisfiedLinkError use) {

Log.e("JNI", "WARNING: Could not load libMimasAr3D.so");

}

}

Something extra (which I don't think that's the main issue)?

In the same file where I load my library, I have this method:

public static native void MIMAS_LoadModel(int ppModel);

Main Activity.java:

//Description: Load the model.

//Input: pModelPath - A file path to the saved model.

//Return: A pointer to the object of the model. NULL if loading is failed.

//Load image to MIMAS_SDK

MimasJNI.MIMAS_LoadModel("models/model.bin");

Kindly please help me with that. Thanks in advance!

解决方案

loadLibrary() takes the name without "lib" prefix.

If you don't use RegisterNatives(), you should name the exported functions of your native library according to javah prescriptions, e.g. Java_com_arzap_mimas_MimasJNI_MIMAS_1LoadModel.

If the native code is C++, make sure the exported functions have extern "C" prefix to pervent name mangling.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值