Hello All,
I have tried very hard to find the process to get the cocos2d-x project work with Android. I finally succeeded and want you to easily install it without any trouble. Please refer to the below tutorials and let me know in case of any issues. I am as well new to this but I will try my best.
Please note that I have never posted anything in any of the forums and I was not aware how to copy the images between the lines. So, I am attaching the word document which can help you in case of any confusion with this.
-
Download Android SDK: Instead of downloading only SDK you can download the ADT Bundle which has a collection of Android SDK, Eclipse and Android Plugin for Eclipse. Download the latest version from http://developer.android.com/sdk/index.html. Extract ADT. I extracted in my E:Drive. My location of the ADT will beE:~~bundle-windows-x86_64-20130717. My location of the SDK will be E:~~bundle-windows-x86_64-20130717\sdk. Also remember to update the SDK. Select the latest version of API and also the Android 2.2 (API 8).
-
Download NDK from http://developer.android.com/tools/sdk/ndk/index.html . I am using a 64 Bit Windows 8 OS. So, I downloaded the version android-ndk-r9-windows-x86_64.zip. Extract the NDK to your C:Drive. I extracted mine at E:~~ndk-r9
-
Download and install Cygwin from http://www.cygwin.com/install.html. Cygwin is a program that enables you to get a Linux feeling on Windows. You can install certain packages on Cygwin and have a minimal Linux like environment. Install Cygwin. When asked to select packages, search for the below packages and install them:
autoconf, automake, binutils, gcc-core, gcc-g**, gcc4-core, gcc4-g**, gdb, pcre, pcre-devel, gawk, make
Note: Select the GUI version of make as well otherwise you will not be able to build your project using NDK. -
Download JDK from http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html. No matter if you system is 32 bit or 64 bit, you need to download only the 32 bit version. Install Java in C:
-
Download the latest version of Cocos2d-X. Extract it to your C:Drive. I extracted mine at E:2d-x-2.2
-
Setup Environment Variables for Java, Cocos2d-x, SDK and NDK:
Mine will look like below:
COCOS2DX_ROOT
E:2d-x-2.2
ANDROID_SDK_ROOT
E:~~bundle-windows-x86_64-20130717\sdk
NDK_ROOT
E:~~ndk-r9
JAVA_HOME
C:_32_Bit\jdk1.7.0_40
If you are not sure how to set the environment variables here is a quick guide: http://www.computerhope.com/issues/ch000549.htm
- Open Cygwin: Right click on the icon and Run as administrator.
- We want to create a new cocos2d-x project now. We will create it for all the platforms and select only the android one later.
cd $COCOS2DX_ROOT
cd tools/project-creator
Now enter the below command to create a new project:
python ./create_project.py~~project TestGamepackage com.MyCompany.TestGamelanguage cpp
A new project will be created under the projects directory. For me it will be in the location E:2d-x-2.2\projects
While running the create_project.py script, If you are seeing some error like:
E:2d-x-2.2\tools\project-creator>create_project.py project MyGamepackage com.webfolks.AwesomeGame language cppproject parameter"
File āE:2d-x-2.2\tools\project-creator\create_project.pyā, line 63
print "Invalid
^
SyntaxError: invalid syntax
Perform the below steps to fix this issue:
Put all the print statements in the create-project.py file in paranthesis.
Original statement:
print āUsage: create_project.py-project PROJECT_NAME-package PACKAGE_NAME-language PROGRAMING_LANGUAGEā
Revised statement:
print (āUsage: create_project.py-project PROJECT_NAME-package PACKAGE_NAME-language PROGRAMING_LANGUAGEā)
- Set Permissions: The problem with the generated new project is that, it is generated using a different user in windows and our actual login will not have access to copy or modify it. For this to work, right click on the generated project folder āTestGameā go to the Security Tab, click Advanced and select the first option. Allow, Everyone, Full Control, This folder subfolders and files. Screen shots below.
Also check the option āReplace all child object permission entries with inheritable permission entries from this objectā This will modify the permissions for all subfolders.
- Now we are done creating a project. To import this to Android we need to build the generated project with NDK. To do this go to cygwin and navigate to the TestGame folder that we created.
Now go to the proj.android folder. Here, we need to run the build_native.sh script. Enter the command:
./ build_native.sh
It will take a while for the build to complete.
Most of you might see an error like:
cygwin warning:
MS-DOS style path detected: E:~~ndk-r9/ndk-build
Preferred POSIX equivalent is: /cygdrive/e/android-ndk-r9/ndk-build
One way to fix this is to go the environment variables and change the NDK_ROOT from E:~~ndk-r9 to /cygdrive/e/android-ndk-r9/ndk-build . If you do this you need to restart cygwin and run the build_native.sh.
I prefer an alternate method where I will edit the build_natiive.sh file and set the NDK_ROOK temporarily.
In Windows, go to the newly created project folder āproj.androidā and then navigate to proj.android. Here you will see a file called build_native.sh. Open this file in any of the text editor and add the below line in the second line:
set $NDK_ROOT = ā/cygdrive/e/android-ndk-r9/ndk-buildā;
With this step there is no need to restart cygwin.
- Now, in cygwin go to the newly created project folder and go to the proj.android folder. Now run the command :
./ build_native.sh
It would take a while for your project to be built.
-
Once this is done copy the entire project to any other location, I choose Desktop\Cocos_Games. Open Eclipse(Remember, you dowloaded the ADT from Android site for SDK and Eclipse), and import the new project. File > Import > Existing Android Code Into Workspace > Next
In the Root Directory click on Browse and navigate till proj.android and click ok.
Note: Do not select āImport to Workspaceā Option. -
You will see some errors in the imported project saying that it certain cocos2d import statements failed to be imported. To fix this follow the below steps(Thanks to Paras Mendiratta):
1: In Eclipse, right-click on your project and select the last option āpropertiesā.
2: In Project Properties window, select āJava Build Pathā in the left pane.
3: Under Java Build Path, select tab āsourceā. It should be selected by default.
4: Click on button āLink Sourceā
5: Browse it to following location-> COCOS2D-X_INSTALLATION_FOLDER/cocos2dx/platform/android/java/src. My path will be: E:2d-x-2.2\cocos2dx\platform\android\java\src
6: Give any folder name. For example, remove src and replace it with: Cocos2d-x-source. Click Finish.
We are done now. Run your poject on an Andorid Device and it should show you the nead cocos2d-x logo. Please note that running this in an Android Virtual Machine may not always work.
Cocos2d-x_Setup_Guide.docx.zip (199.3 KB)