Cocos2D-x示例应用程序在启动时崩溃

时间:2014-03-19 09:09:27

标签: android crash cocos2d-x cocos2d-x-2.x

我尝试使用命令行界面在我的Android设备上构建Cocos2D-x testCpp示例项目(Cocos2D-x 2.2.2),如Readme.md文件中所述:

$ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/
$ export NDK_ROOT=/path/to/ndk
$ ./build_native.sh
$ ant debug install

如果最后一个命令导致sdk.dir缺失错误,则执行:

$ android list target
$ android update project -p . -t (id from step 6)
$ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6)

我可以在我的设备上安装应用程序(Galaxy S4),但应用程序在启动后立即崩溃,告诉我应用程序已停止。

知道我可以做些什么来解决这个问题吗?

我不确定如何在CLI中使用logcat,所以我使用eclipse启动示例应用程序(这里的错误是相同的:启动后应用程序崩溃)并发布eclipse显示的logcat信息:


03-19 10:49:22.785: W/dalvikvm(6591): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/cocos2dx/hellocpp/HelloCpp;
03-19 10:49:22.785: W/dalvikvm(6591): Class init failed in newInstance call (Lorg/cocos2dx/hellocpp/HelloCpp;)
03-19 10:49:22.785: D/AndroidRuntime(6591): Shutting down VM
03-19 10:49:22.785: W/dalvikvm(6591): threadid=1: thread exiting with uncaught exception (group=0x4195f898)
03-19 10:49:22.785: E/AndroidRuntime(6591): FATAL EXCEPTION: main
03-19 10:49:22.785: E/AndroidRuntime(6591): java.lang.UnsatisfiedLinkError: Couldn't load hellocpp from loader dalvik.system.PathClassLoader[dexPath=/data/app/org.cocos2dx.hellocpp-1.apk,libraryPath=/data/app-lib/org.cocos2dx.hellocpp-1]: findLibrary returned null
03-19 10:49:22.785: E/AndroidRuntime(6591):     at java.lang.Runtime.loadLibrary(Runtime.java:355)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at java.lang.System.loadLibrary(System.java:525)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at org.cocos2dx.hellocpp.HelloCpp.(HelloCpp.java:37)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at java.lang.Class.newInstanceImpl(Native Method)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at java.lang.Class.newInstance(Class.java:1130)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.app.Instrumentation.newActivity(Instrumentation.java:1078)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2210)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.app.ActivityThread.access$700(ActivityThread.java:159)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.os.Looper.loop(Looper.java:137)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at android.app.ActivityThread.main(ActivityThread.java:5419)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at java.lang.reflect.Method.invokeNative(Native Method)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at java.lang.reflect.Method.invoke(Method.java:525)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
03-19 10:49:22.785: E/AndroidRuntime(6591):     at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:1)

根据日志,您的建筑物似乎不成功。没有hellocpp.so生成。所以当你调用方法

时它会崩溃
loadLibrary();

您可以在youPath / proj.android / libs / armeabi下查看,查看是否有libxxx.so文件。

答案 1 :(得分:0)

每次发生这种情况都是因为我忘了在相关项目的“proj.android”文件夹中运行./build_native.sh。 @Lorin实际上注意到了提醒我的症状。缺少libxxx.so文件的原因是./build_native.sh脚本尚未运行

当你运行eclipse来构建时,它会在后台发生。当您从命令行编译时,您需要记住至少运行一次脚本(并且每次(如果)您都对cocos2dx框架本身进行了更改。)我经常忘记为 EVERY < / em>之后的项目。