今天接一个安卓的sdk的时候出现了这个问题,具体是调用这个方法是出现的
protected void onLoadNativeLibraries() { try { ApplicationInfo ai = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA); Bundle bundle = ai.metaData; String libName = bundle.getString("android.app.lib_name"); System.loadLibrary("cocos2dcpp"); } catch (Exception e) { e.printStackTrace(); } }
打印出的错误日志是这个
11-08 13:27:43.379: E/AndroidRuntime(14630): FATAL EXCEPTION: main 11-08 13:27:43.379: E/AndroidRuntime(14630): Process: org.cocos2dx.Caribbean.JD, PID: 14630 11-08 13:27:43.379: E/AndroidRuntime(14630): java.lang.UnsatisfiedLinkError: Couldn't load cocos2dcpp from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.cocos2dx.Caribbean.JD-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.cocos2dx.Caribbean.JD-1, /vendor/lib, /system/lib]]]: findLibrary returned null 11-08 13:27:43.379: E/AndroidRuntime(14630): at java.lang.Runtime.loadLibrary(Runtime.java:365) 11-08 13:27:43.379: E/AndroidRuntime(14630): at java.lang.System.loadLibrary(System.java:526) 11-08 13:27:43.379: E/AndroidRuntime(14630): at org.cocos2dx.Caribbean.Caribbean.onLoadNativeLibraries(Caribbean.java:95) 11-08 13:27:43.379: E/AndroidRuntime(14630): at org.cocos2dx.Caribbean.Caribbean.onCreate(Caribbean.java:85) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.app.Activity.performCreate(Activity.java:5295) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2331) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2419) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.app.ActivityThread.access$800(ActivityThread.java:155) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1331) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.os.Handler.dispatchMessage(Handler.java:110) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.os.Looper.loop(Looper.java:193) 11-08 13:27:43.379: E/AndroidRuntime(14630): at android.app.ActivityThread.main(ActivityThread.java:5409) 11-08 13:27:43.379: E/AndroidRuntime(14630): at java.lang.reflect.Method.invokeNative(Native Method) 11-08 13:27:43.379: E/AndroidRuntime(14630): at java.lang.reflect.Method.invoke(Method.java:515) 11-08 13:27:43.379: E/AndroidRuntime(14630): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:859) 11-08 13:27:43.379: E/AndroidRuntime(14630): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:675) 11-08 13:27:43.379: E/AndroidRuntime(14630): at dalvik.system.NativeStart.main(Native Method)
最后在stackoverflow上面找到一个可以解决我这个情况的问题解答
需要确定项目里面是不是libcocos2dcpp这个名字,如下图
在proj.android/jni/Android.mk里面
LOCAL_MODULE_FILENAME := libcocos2dcpp
我的原因就是这个名字被修改过,所以是找不到了。
同时还记得在项目的AndroidManifest.xml文件里面修改相应的字段
<meta-data android:name="android.app.lib_name" android:value="cocos2dcpp" />
解答原文链接:
版权属于:东哥笔记 - DongGe.org
本文链接:http://dongge.org/blog/243.html
自2017年12月26日起,『转载以及大段采集进行后续编辑』须注明本文标题和链接!否则禁止所有转载和采集行为!