Sunday, 13 April 2014

Run Cocos2dx Android Project on Windows

I assume you have already created Android project using template provided with Cocos2dx and imported it in your Eclipse workspace using from existing Android project option and converted it to C/C++ nature.

Also I assume you have installed Android NDK and set up correct path in Eclipse and your workspace location is Cocos2dx default directory.

Note:This method does not require either cygwin or python to run Android project on Windows.

Software's: Cocos2d-x-2.2.2, Windows 8.1 64-Bit and Eclipse 4.4

Step 1: Add Environment Variables

Go to Eclipse -> Window -> Preferences -> C/C++ -> Build -> Environment

And add NDK_ROOT and NDK_MODULE_PATH in Environment variables:


* Note:
If you are using version Cocos2dx-2.2.3 then you don't need to add path for prebuilt modules in NDK_MODULE_PATH. You can only use path F:\Coco2dx\cocos2d-x-2.2.3;

Step 2: Link Resources

Now in your project you have to link your Resources and Classes folders to your eclipse project:

You have to create two folder link named classes and assets If assets folder already exist then delete and recreate it.

To create folder link :
Select Project -> Right Click -> New -> Folder -> Advanced

Linking Classes :
Type classes in folder name and select Link to alternate location (Linked Folder) and type PARENT-1-PROJECT_LOC/Classes

Linking Resources :
Type assets in folder name and select Link to alternate location (Linked Folder) and type PARENT-1-PROJECT_LOC/Resources

Step 3: Setting  C/C++ Builder

Select Project -> Right-Click -> Properties -> C/C++ Build -> Builder-Settings
Uncheck Use default build command option and enter ndk-build.cmd in Build-Command and then click Apply and then click Ok. 

Now eclipse will start building your whole Cocos2dx Android project.

This method build projects faster than Cygwin because Cygwin runs under emulated environment and usually it takes longer time to copy resources to assets directory when you build and run your projects.