Caused by: java.lang.UnsatisfiedLinkError: Cannot load library

when I tried to package an old cocos2dx NDK project, I encountered this problem, apk could be exported but crashed when start running it.

Here is the log I get from eclipse logcat:

FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Cannot load library: reloc_library[1521]:   492 unknown reloc type   160 @      (60218)
	at java.lang.Runtime.loadLibrary(Runtime.java:434)
	at java.lang.System.loadLibrary(System.java:554)
	at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:246)
	at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:260)
	at org.cocos2dx.phonegame.PhoneGameActivity.onCreate(PhoneGameActivity.java:83)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
	at android.app.ActivityThread.access$1500(ActivityThread.java:117)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:130)
	at android.app.ActivityThread.main(ActivityThread.java:3683)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:507)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:880)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:638)
	at dalvik.system.NativeStart.main(Native Method)

First, I clean the project and rebuild it. but the problem is still there.

Then, I find another project and rewrite the Android.mk file under jni folder, but still not ok.

I don't think it's the problem with ndk version, because other project with the same ndk could run perfectly.

At last, I rewrite the Application.mk file under jni folder, this time the ndk compiler rebuild the libc++_static.a and everything is ok.

In a word, this problem in my case is caused by old wrong libc++static.a lib, and only clean the project and rebuild cannot update it.


Solution: Change the Application.mk and force the libc++static.a to be rebuild.
(ps:Maybe delete the obj folder could also make it.)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`java.lang.UnsatisfiedLinkError`是一个Java运行时异常,通常表示在加载本地库(Native Library)时出现问题。 Java程序可以使用Java Native Interface(JNI)来与本地代码进行交互。当Java程序调用本地库时,会尝试加载与该库关联的本地代码。如果在加载过程中发生错误,就会抛出`java.lang.UnsatisfiedLinkError`异常。 这个异常通常有以下几种可能的原因: 1. 本地库文件(通常是`.dll`或`.so`文件)无法找到或加载。在加载本地库时,Java虚拟机会搜索指定的路径,如`java.library.path`系统属性或通过`System.loadLibrary()`方法指定的路径。如果找不到或无法加载本地库文件,就会抛出该异常。 2. 本地库文件与Java程序之间的兼容性问题。本地库可能依赖于特定的操作系统、硬件架构或其他环境参数。如果本地库与当前运行的Java程序不兼容,也会导致该异常。 3. 本地库文件损坏或版本不匹配。如果本地库文件被破坏或其版本与Java程序不匹配,也可能导致该异常。 要解决这个问题,你可以尝试以下几个步骤: 1. 确保本地库文件存在并位于正确的位置。检查文件路径和名称是否正确,并确保文件可访问。 2. 检查本地库文件的兼容性。确保本地库与Java程序的操作系统、硬件架构等参数兼容。 3. 检查本地库文件的完整性和版本。如果文件损坏或版本不匹配,尝试重新下载或更新本地库文件。 4. 检查Java虚拟机的配置。确保`java.library.path`系统属性配置正确,并且指定的路径包含本地库文件。 如果仍然无法解决问题,可能需要进一步调查具体的错误信息和上下文,以确定导致`java.lang.UnsatisfiedLinkError`异常的确切原因。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值