How to create a cocos2d-x v2.2 or higher version project in android

Hi friends. In this tutorial we will learn to create a new project in cocos2d-x 2.2.x versions.
There is a lot of problem in newer versions as the file is missing. Earlier we use to run this file and make project for android. But now some things are changed.We will use mac.
So now assuming that you have already configured eclipse with sdk and ndk, I am moving straight to creation of the project. If you haven’t done the eclipse configuration part, then please visit the below link provided where Ray has written the complete blog for eclipse configuration
Eclipse Setup

Now moving on to creation of the project
Step 1
Navigate to the cocos2dx-2.2.x/tools/project-creator directory and run the following command
python -project YOUR_PROJECT_NAME -package YOUR_PACKAGE_NAME -language cpp
I am taking a project with name cocosSample
Create Project Snap
So now you have created your project successfully
Navigate to the cocos2d-x-2.2.x/projects/cocosSample folder and you will see the folder already created which we use to create earlier with
Screen Shot 2014-06-18 at 2.59.44 pm








Step 2
Now open your folder and you will find a file there. Open the file and add the following lines at the top and save the file
# paths
Provide your ndk root where you have saved your ndk folder
Now the file should look like
Screen Shot 2014-06-18 at 3.02.01 pm



Step 3
Now open the terminal and navigate to cocos2d-x-2.2.x/projects/cocosSample/
Run the file on terminal by writing ./
After you run it will show something like this
After successful run the end output will be like this
Step 4
Start Eclipse and go to File\New\Other. Choose Android\Android Project from Existing Code, and click Next. Click Browse and select the $PROJECT_HOME/ folder, as shown below.
$PROJECT_HOME is the location of your cocosSample project i.e. cocos2d-x-2.2.x/projects/cocosSample
Select Project\Properties from the main menu and choose Java Build Path from the list on the left. In the Source tab click on Link Source and Browse to the following directory
$COCOS2DX_HOME/cocos2dx/platform/android/java/src/ and provide the folder name as cocos2dx_src as shown in snapshot and click Finish and OK.
Java Src
You can now run it. Just build the solution and run
You can see the HelloWorld image
But still some main steps remain

Step 5
The next step is to change the project settings to specify how to run your make command. In the left tree, right click the cocosSample project, select Properties, and select the C/C++ Build section.
Uncheck the Use default build command checkbox, and in the build command textbox type in:
bash ${workspace_loc:/cocosSample}/ NDK_DEBUG=1 V=1
Click apply and then OK
Now just build the solution.It will take some time to build.
Select Project\Build Project from the main menu, and you’ll see the C++ make run in the Eclipse console:
Step 6
In the left tree, right click the cocosSample project and select Properties\C/C++ General\Paths and Symbols\Includes\GNU C++.

Use the Add button to select the two directories shown below, then click Apply and OK.


Click Apply and you might be prompted to re-build the indexes. Go ahead and say Yes and then click OK to close the dialog.

Step 7
Now there is already a folder named classes in the project tree.Just delete the folder from the project.In the left tree, right click the cocosSample project, and select Properties\C/C++ General\Paths and Symbols\Source Location. Click Link Folder, check the Link to a folder in the file system checkbox, and browse to the Classes directory inside the $PROJECT_HOME folder. Click OK, then Apply and OK.
You should now be able to see the Classes directory in your file tree
Eclipse will still have some warnings in the project, but this is just because Eclipse is not that great at parsing C++ header files for the code analyzer stage. To disable this, bring up the project properties (right-click the project and select Properties from the context menu) and turn off the warnings in the Code Analysis section, as you can see in the screenshot below:
Just uncheck all of them and click Apply and OK

Now run the project on a device or emulator. You will see the helloworld default cocos2dx project.Now make some changes in HelloWorldScene.cpp and re run.The change will persist and now you are ready to continue with your cocos2d-x project.
There were some steps earlier which we have not applied in making android project for version 2.2 or above. Hope it helps

1,809 total views, 1 views today

Share this OnShare on FacebookTweet about this on TwitterShare on LinkedInShare on Google+

Leave a Reply