Cuelogic Blog Icon
Cuelogic Career Icon
Home > Blog > All > Configuring cocos2d-X for android on Mac OS

Configuring cocos2d-X for android on Mac OS

Setting up Eclipse, NDK and cocos2d-x for your mac.

  1. I am considering that you already have  Eclipse-Juno/Kepler with android setup.
  2. Download C/C++ development tool from Eclipse. Goto Help->Install New Software Add link Juno – from packages-> Programming Language–> C/C++ development tool.
  3. Download NDK according to your mac compatibility from                                                    
  4. Create “android” folder in the root directory of mac i.e. in Macintosh HD, so that each user of mac will get access to it. And keep android_SDK and android_NDK (currently using version android-ndk-r8) in that folder.
  5. Download cocos2d-x from . Keep it in root folder. For cocos2d-x, you need to set up environment variables (Android_SDK and Android_NDK)
    1. Open “” file in text editor.
    2. Set the path of ndk and sdk. NDK_ROOT_LOCAL=”/android/android-ndk-r8″ ANDROID_SDK_ROOT_LOCAL=”/android/android-sdk-mac_x86″
    3. Save and close the file.

Creating Sample Cocos2d-X project for Android 

  1. Make sure that you have set up the environment variable of cocos2d-x as mentioned above.
  2. In your terminal, go to the root folder of cocos2d-x
  3. Now start creating project. Type “./” and press “Enter”.
  4. It will ask for package name, then type the package name like “com.cue.firstDemoProject” and press “Enter”.
  5. Wait for a sec, it will give you the available android version list                                    
  6. Then it will ask for target id i.e. Android version you want to set from above available list
  7. Here I have selected id: 3 as I want to set android version 2.1 and above and press “Enter”.
  8. It will ask for project name, then type the name e.g. FirstDemoProject                                
  9. Now you are done with creating the project. It is stored in cocos2d-x folder.
  10. Go to the folder of created project e.g.“FirstDemoProject”. Then go to “” folder.
  11. Open “” and reset the path of COCOS2DX_ROOT=”/cocos2d-2.1beta3-x-2.1.0″. Save and close file.
  12. Now open project in eclipse
  13. Eclipse File–>New–>Other. Select Android–>Android project from existing code and “Next”CAMadd in eclipse 1
  14. Browse to your project like FirstDemoProject-> and “Finish”                                 CAMadd in eclipse 2
  15. It will show the project in Package Explorer
  16. Now import the Java in Package Explorer. File–>New–>Other. Select Android–>Android project from existing code. Browse to cocos2d-x Folder/cocos2dx/platform/android/java and “Finish”. It will add “libcocos2dx” in Package Explorer.                                                                                                                                                         CAMadd in eclipse 3
  17. Convert the project to C/C++ project. File–>new–>other select C/C++->Convert to C/C++ and “Next”. Check if  “FirstDemoProject” is selected and press “Finish”. And open it in C/C++ perspective–>YES.                                                                                CAMadd in eclipse 4
  18. Now you need to set up project properties. So right click on project and go to “Properties”
  19. For Android tab, set “Project Build Target” to higher android version and add “libcocos2dx” and press “Apply”.
  20. For C/C++ Build option, uncheck the “use default command ” and set Build command like “bash ${workspace_loc:/FirstDemoProject}/ NDK_DEBUG=1 V=1”                                                                                                                                                                                              CAMadd in eclipse 5

i. For Environment option, add environment variable Name “NDK_ROOT” and path “/android/android-ndk-r8” i.e ndk path in file system and “Apply”

CAMadd in eclipse 6


21. For C/C++ General option,

i.   For Code Analysis, enable “Use Project settings” and unmark all check box.

ii. For Paths and Symbols,

(a) For “include” tab , select “GNU C++” language and press “Add” you will get popup for “Add directory path”. Select “File System” and include following directories :

I) /android/android-ndk-r8/platforms/android-3/arch-arm/usr/include

II) /cocos2d-2.1beta3-x-2.1.0/cocos2dx/include

III) /cocos2d-2.1beta3-x-2.1.0/CocosDenshion/include

(b) For Source Location option, set classes and resources path. Select “link Folder” it will open a new pop up and enable checkbox “Link to folder in file system” and browse classes and Resources location in project directories. This will add the folder “Classes” and “Resources” in Project explorer.

(c)  Click on “Apply” and then “OK”.

22. Now clean  and build the project. It will build all the library of cocos2d-x, you can check it in “Console”.

23. Now run as Android project. After running you will see the “Hello world” screen.                                                                       CAMRun on device


24. Congratulations, you have successfully run the cocos2d-X project on Android.