的UnsatisfiedLinkError调用来自本地库方法时,虽然的System.loadLibrary似乎确定 [英] UnsatisfiedLinkError when calling method from native library although System.loadLibrary seems ok
问题描述
我有一个Android 1.2.2工作室项目设置一些本地* .so文件包含在项目 - > SRC - >主 - > jniLibs - > armeabi(这是正确的架构,他们)。我有一个加载库在静态和链接到本地方法(我想/希望)。
一类下面是静态与的System.loadLibrary:
静态{
尝试 {
的System.loadLibrary(<有的LIB>);
}赶上(ULE的UnsatisfiedLinkError){
Log.e(TAG,错误而载入库<有的LIB>中,ULE);
}
}
我从来不打catch块,或看到错误消息,但我已验证我输入静态和到达的System.loadLibrary行,所以我不认为我打一个问题加载。
我有这样的进口在另一个类:
进口玉米和LT;休息-OF-pacakage-名称><有的LIB>
和具有本地方法初始化,需要一个字节:
公共本地静态INT<有的LIB> _initialize(byte []的参数);
这是基于全部关闭另一个Eclipse项目,我移植过的AS。
任何意见/建议或办法,我可以找出为什么库加载似乎是美好的根本原因,但该方法调用不是?
8月7日至22日:38:51.810 27119-27119 / COM<休息的包名 - > .staging E /艺术:没有执行发现INT COM&LT ;休息-OF-包名称> .pppp_api.PPPP_APIs.PPPP_Initialize(字节[])(试过Java_com_<其余的包名 - > _pppp_1api_PPPP_1APIs_PPPP_1Initialize和Java_com_<其余-OF-包名称> _pppp_1api_PPPP_1APIs_PPPP_1Initialize ___ 3B)
8月7日至22日:38:52.360 27119-27119 / COM<休息-OF-包名称> .staging E / AndroidRuntime:致命异常:主要
。过程:COM<休息-OF-包名称> .staging,PID:27119
java.lang.UnsatisfiedLinkError中:没有执行发现INT COM< _pppp_1api_PPPP_1APIs_PPPP_1Initialize和Java_com_<&GT休息,封装名称的;休息-OF-包名称> .pppp_api.PPPP_APIs.PPPP_Initialize(字节[])(试过Java_com_<。休息的包名 - > _pppp_1api_PPPP_1APIs_PPPP_1Initialize ___ 3B)
在COM<休息的包名 - > .pppp_api.PPPP_APIs.PPPP_Initialize(本机方法)
在COM<休息-OF-包名称> .ui.base.BaseDrawerActivity.setupDrawer(BaseDrawerActivity.java:150)
在COM<休息-OF-包名称> .ui.base.BaseDrawerActivity.onCreate(BaseDrawerActivity.java:99)
在COM<休息-OF-包名称> .ui.main.MainActivity.onCreate(MainActivity.java:15)
在android.app.Activity.performCreate(Activity.java:6221)
在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2614)
在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
在android.app.ActivityThread.access $ 900(ActivityThread.java:172)
在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1421)
在android.os.Handler.dispatchMessage(Handler.java:102)
在android.os.Looper.loop(Looper.java:145)
在android.app.ActivityThread.main(ActivityThread.java:5835)
在java.lang.reflect.Method.invoke(本机方法)
在java.lang.reflect.Method.invoke(Method.java:372)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1399)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
有关类包含静态和本地方法包名称:
包COM<其余--的包名称> .pppp_api;
1)如果您更改包的名称包含本地方法的类,你应该改变方法签名本土code。
2)尝试创建一个更fodler名为armeabi-V7A及复印件*。所以有,因为有些设备不能使用旧armeabi而忽略库在fodler
3)模块graddle脚本中添加此行内的机器人块:
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir钢骨混凝土/主/ jniLibs
}
I have an Android Studio 1.2.2 project setup with some native *.so files included in project -> src -> main -> jniLibs -> armeabi (that's the correct architecture for them). I have a class that loads the library in a static and links to the native methods (I think/hope).
Here is the static with System.loadLibrary:
static {
try {
System.loadLibrary("<SOME LIB>");
} catch(UnsatisfiedLinkError ule){
Log.e(TAG, "Error while loading library <SOME LIB>", ule);
}
}
I never hit the catch block or see the error message but I have verified I enter the static and get to the System.loadLibrary line so I don't assume I'm hitting an issue loading it.
I have this imported in another class:
import com.<rest-of-pacakage-name>.<SOME LIB>
and has a native method initialize that takes a byte:
public native static int <SOME LIB>_Initialize(byte[] Parameter);
This was all based off of another eclipse project that I'm porting over the AS.
Any ideas/suggestions or ways I can identify the root cause of why the library load seems to be fine but the method call not?
07-22 08:38:51.810 27119-27119/com.<rest-of-package-name>.staging E/art﹕ No implementation found for int com.<rest-of-package-name>.pppp_api.PPPP_APIs.PPPP_Initialize(byte[]) (tried Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize and Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize___3B)
07-22 08:38:52.360 27119-27119/com.<rest-of-package-name>.staging E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.<rest-of-package-name>.staging, PID: 27119
java.lang.UnsatisfiedLinkError: No implementation found for int com.<rest-of-package-name>.pppp_api.PPPP_APIs.PPPP_Initialize(byte[]) (tried Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize and Java_com_<rest-of-package-name>_pppp_1api_PPPP_1APIs_PPPP_1Initialize___3B)
at com.<rest-of-package-name>.pppp_api.PPPP_APIs.PPPP_Initialize(Native Method)
at com.<rest-of-package-name>.ui.base.BaseDrawerActivity.setupDrawer(BaseDrawerActivity.java:150)
at com.<rest-of-package-name>.ui.base.BaseDrawerActivity.onCreate(BaseDrawerActivity.java:99)
at com.<rest-of-package-name>.ui.main.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6221)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2614)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.access$900(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1421)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5835)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Package name for class that contains the static and native method:
package com.<rest-of-package-name>.pppp_api;
1) If you change package name for class that contains native methods, you should change method signature in native code.
2) Try create one more fodler with name armeabi-v7a and copy *.so there because some devices can't use old armeabi and ignore libs in that fodler
3) in module graddle script add this lines inside "android" block:
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/jniLibs'
}
这篇关于的UnsatisfiedLinkError调用来自本地库方法时,虽然的System.loadLibrary似乎确定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!