1

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

$ 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)

4

2 回答 2

1

根据日志,您的构建似乎不成功。没有生成 hellocpp.so。所以当你调用该方法时它会崩溃

loadLibrary();

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

于 2014-04-30T03:18:51.287 回答
0

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

当您运行 eclipse 来构建它时,它会在后台发生。当您从命令行编译时,您需要记住至少运行一次脚本(并且每次(如果)您曾经对 cocos2dx 框架本身进行过更改。)我经常忘记为之后的每个项目执行此操作。

于 2014-09-20T08:45:09.300 回答