I tried to build the Cocos2D-x testCpp sample project (Cocos2D-x 2.2.2) on my Android device using the command line interface as described in the Readme.md file:
$ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/
$ export NDK_ROOT=/path/to/ndk
$ ./build_native.sh
$ ant debug install
If the last command results in sdk.dir missing error then do:
$ 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)
I can install the app on my device (Galaxy S4) but the application crashes immediately after the launch telling me the application was stopped.
Any idea what I can do to fix that problem?
I am not sure how to use logcat within the CLI, so I startet the sample application using eclipse (the error here is the same: application crashes after launch) and post the logcat info shown by eclipse:
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)
seems that your building is not successful according to the log. no hellocpp.so is generated. so it crashes when you call the method
loadLibrary();
you can check this under youPath/proj.android/libs/armeabi , see if there's a libxxx.so file.
Every time this has happened to me it has always been because I forgot to run ./build_native.sh in the "proj.android" folder of the project in question. @Lorin actually noted the symptom that reminded me. A reason that a libxxx.so file would be missing is the ./build_native.sh script has yet to be run
When you run eclipse to build it is happening in the background. When you compile from command line you need to remember to to have run the script at least once (and every time (if) you ever make a change to the cocos2dx framework itself.) I frequently forget to do that for EVERY project thereafter.
来源:https://stackoverflow.com/questions/22500867/cocos2d-x-sample-application-crashes-on-launch