Eclipse Android setup

Eclipse Android setup
0.0 0


Hey there, fair warning, I’m new to both the forums and cocos2d-x so prepare for some newb questions :wink:

I’m just wanting to start developing Android apps with Cocos2dx, not iOS or Windows or anything else, just Android. Mainly because I don’t have any apple hardware, and it costs $100 a year, so yeah, all I want is a project in Eclipse that I can deploy to an Android device.

My current OS is Fedora 17 (Linux Distro)
And I’m using Eclipse Juno (Android Developer Tools Bundle) This comes with the SDK, AVD and CDT already installed. I’ve also setup the NDK with Eclipse.

Just a note, I HAVE got some cocos2dx samples running on an Android Device, but they’re dodgy as fuck, and I don’t have any idea where to go from there.
By dodgy I mean once I load them into Eclipse I can debug them fist time, but once I open main.cpp I get a whole bunch of errors and I can’t debug again. Strange I think.

In particular, the errors are due to unresolved include statements, and believe me, I’ve seared Google. Like every website on the first 10 pages of Google.
I’ve read countless tutorials on this but they all stop me at this same point.

So what I’m really asking for is a basic understanding of how Cocos2dx handles things like libraries and stuff.

So does cocos2dx use the cocos2d library with a C++ wrapper or does it have it’s own version of the engine?
In an Android project, where do I put the Engines such as CocosDension, Cocos2d, Cocos2dx, and libCocos etc… Do they just need to go in the same workspace, or under the src folder, of what?
I’ve also read that you need to put some Include path’s in, in Eclipse, and I can do that, but they all come with the error that the paths are wrong?

I’ve been at this for like 2 weeks straight with a lot of late nights, so believe the forums wasn’t my first choice for help.

Thanks in advance for any replies,


As you said, you have succeeded running examples on Android devices. So my suggestion is that you know the meaning of every steps. If you have any question about any step, then you can answer a question here. And i think the wiki pages in this forum.


Thanks for the near INSTANT reply Minggo,

Yes, I’ve got some samples running, but I’m more wanting an understanding of Cocos2dx, not a running app.

I’ve looked at some of the wiki as you suggested, and I think my head was getting cluttered with the abundance of bash and terminal files associated with Android :wink:

I looked at another sample for iOS and Android and the folder structure looks something like this…


This is making more sense now.

Correct me if I’m wrong.

So the classes you create go in “Classes”, and your resources in “Resources”?

Then in libs you have the cocos2dx engine and CocosDenshion.

CocosDenshion confuses me though; can someone please explain what that is used for?
Also, what’s the difference between the “assets” folder in “android”, and “Resources” as they seem to have the same contents?

So I think I’ve almost got my head around the file structure, now my biggest problem is Eclipse.

As I’ve said, I can’t seem to get it to recognize the include statements, so if anyone knows how to do that?

And last of all, is there anyway to open this whole folder structure in Eclipse, or can I only open the Android project?

Thanks again in advance,


Hi there!

I can’t help you with everything behind Cocos or CocosDenshion but I can help you with your Eclipse problem :wink:
(At least I hope I can ^^)

Before I start, I am new to cocos, spent a lot of time to build and run a custom project. Actually I still have a problem, where every little changes I make to the project (Like changing “Hello World” to “My World”) gives me a 1 to 2 minute build, which is just annoying as hell!
Hope you won’t run into the same problem as me :stuck_out_tongue:

First, everything in the folder Resources is copied in the assets folder of your Android project. This way you share between platforms and keep the “Android part” in its own folder (
Classes holds your logic classes (so kind of everything!)

I don’t know everything you did in Eclipse so I will summarize quickly all the steps you need to do to get it right :

  1. Import the java project :
  2. Convert to a C*+ project : Right click, Add~~>New~~>C/C**>Convert to a C/C*+ Project with project type “Makefile project”
    # Then you have to add the “Classes” folder, go to your project properties -> C/C*+ General
    > Paths and Symbols. Then choose the “Source Location” tab and click on the “Link Folder” button. Check “Link to folder in the file system” and browse to the Classes folder.
    So now you have your java project and the Classes folder inside it so you can code everythin in Eclipse.
    Now, the million error detection, quite easy :
    Still on the “C/C*+ General" option, go to “Code Analysis” then check the “Use project settings” or “configure worspace settings” . Then, when you see the “Syntax and Semantic Errors”, uncheck it .
    You may still have some Java problems .
    For that, you have to import the “libcocos2dx” java project. It should be located in cocos2d-whatever/cocos2dx/platform/android/java.
    That should solve the remaining java errors. Maybe still some warnings, can’t be perfect :stuck_out_tongue:
    The last thing you may want to have, is the help inside Eclipse .
    For that, you need to import some libs !
    Go back to your “Paths and Symbols” option, “Includes” tab. Select the “GNU C**” languages and click the “Add…” button to add the needed libs :
    * cocos2dx
    * cocos2dx/include
    * cocos2dx/platform/android
    * android-ndk/platforms/android-8/arch-arm/usr/include/android
    the “cocos2dx” folder is inside the “cocos2dx-2.0-x-2.0.4” folder .
    The android-8 is because I use the API 8 for my project. So choose the one you need :wink:
    After all that, you should have no errors, help with functions and good colorisation of your C*+ code.
    The last thing is to build the actual project inside Eclipse :
    Go to”C/C*+ Buid" option, uncheck “Use Default build command” and use the following command :
    >> bash ${workspace_loc:/projectNameHere}/ NDK_DEBUG=1 V=1 <<

And that should be it !

You may have done some of those steps already, hope it helps :wink:



Thanks for the reply Frany,

I’m still running in to some problems though.

Firstly, when I run the app, I just get a black screen?
And I’ve got a warning saying “Invalid project path: Include path not found (home/Daniel/Development/Software/cocos2dx/cocos2d-2.0-x-2.0.4/cocos2dx).”
Which is the first include statement you told me to put in.

Also in the jni/helloworld/main.cpp it can’t find the include statements
#include <jni.h>
#include <android/log.h>

And I laughed so hard when you basically said, “to get rid of the errors, hide them…,”

Thanks once again for the in-depth reply,

I’ll keep tinkering with this.


Okay, so I’ve had another try, but I’ve now got this really wired error with the NDK.

I solved the include statements, don’t know how, I just did all your steps again, and it’s fine now?

So anyway, I build the project, and it says:
/home/Daniel/Development/Software/ndk/build/gmsl/__gmsl:513: *** non-numeric second argument to `wordlist’ function: ‘’. Stop.

So it’s starts building it fine, but there’s something wrong with an NDK file???

So I googled the error:!msg/android-ndk/b4DSxE1NAS0/X8djK5cP7q0J

And someone said to change this:
int_encode = $(__gmsl_tr1)$(wordlist 1,$1,$(__gmsl_input_int))

to this :
int_encode = $(__gmsl_tr1)$(wordlist 1,$(words $1),$(__gmsl_input_int))

Which from what I can gather addresses the problem.

So I did a build and clean in Eclipse and I get this now:
/home/Daniel/Development/Software/ndk/build/gmsl/__gmsl:513: *** missing separator. Stop.

Okay, the same line is failing, but now there’s a missing separator?

Any ideas?
Is there something wrong with my NDK version :

Thanks again for fixing everything else though. Even though you’ve broken something else ;).

I didn’t want to do 3 posts in a row, so I’ll edit this one.

I googled the error (should have done that first) and it’s was obviously a rouge space in the line :wink:

So now I do a build and clean and I get this…

**** Build of configuration Default for project Pong ****

bash /home/Daniel/Development/Projects/PongSample/android/ NDK_DEBUG=1 V=1 all
make: Entering directory `/home/Daniel/Development/Projects/PongSample/android’
/home/Daniel/Development/Software/ndk/build/core/ Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion in ./AndroidManifest.xml

------------Deleted some here------------------

jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp -o ./obj/local/armeabi/objs-debug/cocos2d/effects/CCGrabber.o
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp: In constructor ‘cocos2d::CCGrabber::CCGrabber()’:
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp:46:32: error: ‘glGenFramebuffersOES’ was not declared in this scope
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp: In member function ‘void cocos2d::CCGrabber::grab(cocos2d::CCTexture2D*)’:
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp:61:47: error: ‘glBindFramebufferOES’ was not declared in this scope
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp:65:26: error: ‘glFramebufferTexture2DOES’ was not declared in this scope
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp:68:63: error: ‘glCheckFramebufferStatusOES’ was not declared in this scope
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp: In member function ‘void cocos2d::CCGrabber::beforeRender(cocos2d::CCTexture2D*)’:
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp:88:47: error: ‘glBindFramebufferOES’ was not declared in this scope
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp: In member function ‘void cocos2d::CCGrabber::afterRender(cocos2d::CCTexture2D*)’:
make: Leaving directory `/home/Daniel/Development/Projects/PongSample/android’
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp:113:50: error: ‘glBindFramebufferOES’ was not declared in this scope
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp: In destructor ‘virtual cocos2d::CCGrabber::~CCGrabber()’:
jni/…/…/libs/cocos2dx/effects/CCGrabber.cpp:127:35: error: ‘glDeleteFramebuffersOES’ was not declared in this scope
make: *** [obj/local/armeabi/objs-debug/cocos2d/effects/CCGrabber.o] Error 1

**** Build Finished ****

The 3rd line says :warning: APP_PLATFORM android-14 is larger than android:minSdkVersion in ./AndroidManifest.xml

That makes no fucking sense what so ever, why is it complaining the platform is LARGER than the MINIMUM?

The rest is a whole bunch of building crap.

Then the last couple of lines are some more errors about libs/cocos2dx/effects/CCGrabber.cpp

My only theory on that is the Pong sample was built with an older version of the cocos engine and now the new one is throwing an error because of some feature, but I don’t know.

So I went from having one error, to 9.
I might break that ndk file again ;).


Hi again!

I have no idea what is going on with the ndk errors. I didn’t have those errors so I can’t tell you what’s wrong :-/ (I am using version r8c)

For the API warning, I suppose it just something to change in the manifest (the minimum API you want and the one you actually use I think).
Or it may be because of the ndk version you included in your project (you have one lib for every API version)

Try to create a simple project with the “create-android-project” script and see what it does !

Good luck!


Thanks again,

I did some more googling and found this:

And all I had to do was provide a minSDK in the AndroidManifest.xml!


Everything built again, and I have the 9 errors about CCGrabber

So, i’ll edit this is I figure out some more.

Thanks again,


Holy Komoly,

Something works

Okay, as you suggested, I created a new project using the

  1. I then changed the to suit my environment
  2. Imported it into Eclipse.
  3. Converted it into a C/C++ project
  4. Linked the Classes, and Resources folders that were generated.
  5. Imported those include file thingies
  6. cocos2dx/include
  7. ndk/platform/android-8/urs/arch-arm/include
  8. made a makefile in the project directory with the following code
    ant Dsdk.dir=/home/Daniel/Development/Software/sdk debug
    d uninstall org.cocos2dx.test
    adb d install bin/test-debug.apk
    d logcat | grep cocos2d
    rm rf libs/
    rf obj/
    rm rf bin/*
    rf gen/
    rm -rf assets/*

and i think that’s about it.
It runs perfectly on both a device and AVD :D:D:D:D:D:D:D:D:D:D::D:D:D:D:D:D:D:D:D:D:.

I know I’m probably going to screw something up soon or run into another error, but atleast I have a clean, uptodate project running.

I can’t thank you enough Frany G!

I used that makefile instead of the oode you provided simply because I find it easier to understand what’s happening.

Also, I realised why I can’t move projects out of the Cocos2dx directory; because the build_native doesn’t actually refer to a static directory but uses …/…/ and things, if that made sense.

So, if I wanted to move the project out of the cocos2dx directory is there something I can do, or do I have to hand modify the entire of the project?

Secondly, my build times are insanely slow, which I’m pretty sure is what you’re having trouble withe Frany G.

That’s another reason why I used this makefile (BTW sourced from here :
I can see exactly what’s it’s going to do when I clean, run or build (all) the project.
So I’ll have a tinker with this file once I have a clearer understanding of cocos2dx.

Thanks once again Frany G,



Glad to hear it finally works =)

If you find anything for the build times, I’ll be happy to see it :slight_smile:

Previously Frany G :stuck_out_tongue:


I’m in the same boat as you guys. Android development on Linux with Eclipse. I have the slow build times too, but at this point that isn’t what is bothering me.

I can’t figure out how to run any of the XCode specific tutorial examples. Have you had any luck figuring out how to follow any of those tutorials using the android project structure?


You should check this:

I modified to this:

JOBS=$(cat /proc/cpuinfo 2>/dev/null|grep -m1 "cpu cores"| awk -F": " '{print $2}')
if [ -z "$JOBS" ]; then
echo "Build with $JOBS parallel jobs"
@if [[ “$buildexternalsfromsource” ]]; then@
@ echo “Building external dependencies from source”@
@ “$NDK_ROOT”/ndk-build C “$APP_ANDROID_ROOT” $* —jobs=$JOBS@
@ echo “Using prebuilt externals”@
@ “$NDK_ROOT”/ndk-build

So it will build on multi threads, what will speed up building.