cocos2d-x first project coudn't run on android and stopped

Hi,

I am a beginner in cocos2d-x. I followed the steps in the “Game Development Essentials” one by one.
I use the following:

  • cocos2d-x 3.5
  • eclipse with adt,
  • ant 1.9.4
  • ndk r9d
  • java 1.8.0_40
  • android sdk
  • genymotion as a virtual machine.

When I build the project it succeeds but if I try to run as android application i get error messages in LogCat (please see the attached files)

I am very confused. I’ve been working on that since yesterday at this time.
Please help me…

logs.zip (1.6 KB)

Your android program is only a frame to run cocos2dx game.
It needs to load your cocos2dx game library only then it will run it.
Before Eclipse builds Java program it will first run the build_native.py to compile the cocos2dx library.
By looking at your build_log.txt, that your cocos2dx game libary failed to be compiled.

Exception: Build dynamic library for project [ C:\Users\Mus-T\Desktop\ColorSlide\proj.android…/ ] fails!

Therefore when you run your Android program it cannot find the library showing

04-29 22:16:26.724: E/AndroidRuntime(1321): FATAL EXCEPTION: main

Thanks for the fast answer but saying what I can read in the log files does not solve the problem. I want to know why it fails and what I can do to make it build successfully.

I think most probably it is something wrong with your Android SDK path, as what shown in your log

Android platform not specified, searching a default one…
running: ‘“C:\SDK\sdk\tools\android” update project -t android-19 -p C:\Users\Mus-T\Desktop\ColorSlide\proj.android’

Can you try running <COCOS_ROOT>\setup.py and let us see what is the path for your Android SDK?

sure, here it is:

the problem is:
if I build it (build_native.py) for the first time after creating the project with “cocos new NAME -p PACKAGE -l LANGUAGE -d DESTINATION” it builds everything correctly on the console…
but if I import the whole project (proj.android & libcocos2dx) into eclipse it makes the errors in the logfile

Can you check if the libcocos2dcpp.so exists in your proj.anroid/libs/armeabi folder?
If it exists, then maybe you can turn off the c++ build command setting in Eclipse like this
Just create a dummy file to let Eclipse execute so it won’t bother the NDK build process.

Else you can refer to the tutorials here
http://www.cocos2d-x.org/wiki/How_to_run_cpp-tests_on_Android
http://www.cocos2d-x.org/wiki/How_to_Build_an_Android_Project_with_Eclipse

What do you mean with “create a dummy file”?
If I do that exactly like your screenshot it says
“Cannot run program “bash”: Launching failed
Error: Program “bash” not found in PATH”

Those two links you just send me, I already know them by heart (did that for at least 15 times) ^^

ok, there it is…

You need to use build_native.py from cocos 3.4 to work (3.5 and 3.6 is broken). After it, if you compile and run, and get a ‘srand’ error, you need to specify android api level on application.mk

2 Likes

okay, thanks I’m gonna try that one… although there is a 3.6 since 2 days… I will try both of them :smile:

Normally I will compile the library file in command prompt with build_native.py
Then i will create a build_native_dummy.py the content is only like this

“#!/usr/bin/python”
“# build_native.py”
“# Build native codes”

(Without quotes)

If your cocos2dx library has already been compiled your program should run with Eclipse.