从System.loadLibrary看起来不错,从本机库调用方法时出现UnsatisfiedLinkError
作者:互联网
我有一个Android Studio 1.2.2项目设置,项目中包含一些本机* .so文件-> src->主-> jniLibs-> armeabi(这是适合他们的正确体系结构).我有一个类,以静态方式加载库并链接到本机方法(我认为/希望).
这是System.loadLibrary的静态内容:
static {
try {
System.loadLibrary("<SOME LIB>");
} catch(UnsatisfiedLinkError ule){
Log.e(TAG, "Error while loading library <SOME LIB>", ule);
}
}
我从没有碰到catch块,也没有看到错误消息,但是我已经验证我输入了静态代码并进入了System.loadLibrary行,因此我不认为我在加载它时遇到了问题.
我将此导入另一类:
import com.<rest-of-pacakage-name>.<SOME LIB>
并具有一个需要一个字节的本地方法initialize:
public native static int <SOME LIB>_Initialize(byte[] Parameter);
这全都是基于我正在AS上移植的另一个Eclipse项目的.
有什么想法/建议或方法可以找出导致库加载看起来很好但方法调用不正确的根本原因?
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 com.<rest-of-package-name>.pppp_api;
解决方法:
1)如果更改包含本机方法的类的程序包名称,则应在本机代码中更改方法签名.
2)尝试再创建一个名称为armeabi-v7a的fodler并复制* .so,因为那里的某些设备无法使用旧的armeabi并忽略该fodler中的库
3)在模块Gradle脚本中,在“ android”块中添加以下行:
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir 'src/main/jniLibs'
}
标签:android,android-studio,android-ndk,nativelibrary 来源: https://codeday.me/bug/20191013/1904513.html