Easy Guide to setup the cocos2d-x for android in Windows

Easy Guide to setup the cocos2d-x for android in Windows
0.0 0

#1

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.

  1. 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).

  2. 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

  3. 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.

  4. 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:

  5. Download the latest version of Cocos2d-X. Extract it to your C:Drive. I extracted mine at E:2d-x-2.2

  6. 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

  1. Open Cygwin: Right click on the icon and Run as administrator.
  2. 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 TestGame package 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 cpp
File “E:2d-x-2.2\tools\project-creator\create_project.py”, line 63
print "Invalid
project parameter"
^
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”)

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  2. 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)


Running Build-Win32.bat on windows7
[Help] Can't install cocos2d-x in win 8
#2

It looks great. Thank you.
On the other hand, I am trying to build for android via MSVC 2012 Express + vs-android (http://code.google.com/p/vs-android/). See if I could get positive results :slight_smile:


#3

I am using VS 2010 Ultimate and it worked for me.

Did you do this step?
For Vista or Windows 7 you will need to right click ‘install_vs20XX.cmd’, and choose to ’Run as Administrator".

Are you getting any error?


#4

@Sriram Kumar Bikkina : Hi! Thank you for your tutorial. I did it follow your guide conveniently from start to 11th step. But on the 12th step, when I import my project into Eclipse, I have a error like:
program “bash” is not found in PATH
I’m a beginner. Please help me for this problem. Thank a lot :slight_smile:


#5

Hi Nquyen,

In Step 11, did you compile with ./build_native.sh (I meant did you add “./” before the shell script?)

Also can you let me know the version of Eclipse you are using? Is it downloaded from the Android Developer Site?

Also please confirm if you are only importing the proj.android folder.

Nguyen Truong Minh wrote:

@Sriram Kumar Bikkina : Hi! Thank you for your tutorial. I did it follow your guide conveniently from start to 11th step. But on the 12th step, when I import my project into Eclipse, I have a error like:
program “bash” is not found in PATH
I’m a beginner. Please help me for this problem. Thank a lot :slight_smile:


#6

@Sriram Kumar Bikkina : Thank you for the reply! I did it step by step, until Step 11, I typed “sh build_native.sh”. And I also downloaded the latest version of “ADT Bundle”. In Step 12, I imported the project by navigating till proj.android folder. Please look at this picture : [[http://i609.photobucket.com/albums/tt173/minhnt_bkhn/Untitled_zpsf5c3f9a0.jpg]] . Please tell me when you find any mistakes. Thank you !


#7

Hello, How can I find the gcc4-core and gcc4-g++ cygwin packages? I found the others except this two. :confused:


#8

Sriram Kumar Bikkina wrote:

I am using VS 2010 Ultimate and it worked for me.
>
Did you do this step?
For Vista or Windows 7 you will need to right click ‘install_vs20XX.cmd’, and choose to ’Run as Administrator".
>
Are you getting any error?

Problem is that I am able to compile sample vs-android project while I do not know how to setup for cocos2d-x projects:)


#9

That is the problem with VS Android. No where they mentioned about how to create a new project. When I googled, I found that there is no way to create a new project with vs-adnroid. Only thing you can do is to edit one of the sample projects and start building your project.
winipcfg exe wrote:

Sriram Kumar Bikkina wrote:
> I am using VS 2010 Ultimate and it worked for me.
>
> Did you do this step?
> For Vista or Windows 7 you will need to right click ‘install_vs20XX.cmd’, and choose to ’Run as Administrator".
>
> Are you getting any error?
>
Problem is that I am able to compile sample vs-android project while I do not know how to setup for cocos2d-x projects:)


#10

Jair,

Just try the search work ‘GCC’ and you will find a lot of packages. In the install the below list and as well any others which you think would be necessary.

cygwin32-gcc-core: GCC for Cygwin 32bit toolchain (C, OpenMP)
gcc-core: GNU COmpiler Collection (C, OpenMP)
gcc-g**: GNU Complier Collection
GCC C runtime library

Jair Humberto da Silva Filho wrote:

Hello, How can I find the gcc4-core and gcc4-g** cygwin packages? I found the others except this two. :confused:


#11

You do not need Cygwin for Windows Android.

Cygwin will just make it too complex. use ndk-build.cmd


#12

Hi Nguyen,

I did check this again and did not see any issues on my PC. I googled as well on this error and I found that it might be related to the issues with the NDK Build. So, I think your code might not be properly build for android using NDK. I suggest you go through some alternative way to build your native code using NDK. Cory Trese suggested a good way to go with this.

Nguyen Truong Minh wrote:

@Sriram Kumar Bikkina : Thank you for the reply! I did it step by step, until Step 11, I typed “sh build_native.sh”. And I also downloaded the latest version of “ADT Bundle”. In Step 12, I imported the project by navigating till proj.android folder. Please look at this picture : [[http://i609.photobucket.com/albums/tt173/minhnt_bkhn/Untitled_zpsf5c3f9a0.jpg]] . Please tell me when you find any mistakes. Thank you !


#13

Sriram Kumar Bikkina wrote:

That is the problem with VS Android. No where they mentioned about how to create a new project. When I googled, I found that there is no way to create a new project with vs-adnroid. Only thing you can do is to edit one of the sample projects and start building your project.
winipcfg exe wrote:
> Sriram Kumar Bikkina wrote:
> > I am using VS 2010 Ultimate and it worked for me.
> >
> > Did you do this step?
> > For Vista or Windows 7 you will need to right click ‘install_vs20XX.cmd’, and choose to ’Run as Administrator".
> >
> > Are you getting any error?
>
> Problem is that I am able to compile sample vs-android project while I do not know how to setup for cocos2d-x projects:)

I am trying to convert the win32 solution to Android. After updating definitions, configurations and seems like everything is still like a mess :stuck_out_tongue:

Is it possible to give us some tips on how to setup and compile a cocos2d-x sample? Thanks.


#14

Jair Humberto da Silva Filho wrote:

Hello, How can I find the gcc4-core and gcc4-g++ cygwin packages? I found the others except this two. :confused:

Configuring stuff these days is such a nightmare and all the missing pieces to find, conflicts and where do I have to jump through what hoops to get this piece of junk to build…

What would be heroic, if someone would build a virtual machine, (VMWare, Virtual PC, Virtual Box, whatever) that had an O/S (any I don’t care but Linux would be legal) and a pre-installed Cocos2dx development environment for Android development.

That would be would get kudos by the bucketful from me.

I’ve been messing about with SailfishOS SDK, Tizen SDK, and other useless pieces of crap. I am thoroughly sick and tired of installing things that don’t work, require conflicting plugins or are just thoroughly a sick joke. There is no Windows8 installer and the Windows7 installer won’t install on Windows8, the OS-X installer won’t install on the current version of OS-X because it seems to rely on an OS-X version two whole point releases ago. Back to Cocos2dx, Windows Phone8 won’t even build release versions out of the box, how hard can it be to change the freaking drop down from Debug to Release before packaging a build. http://www.cocos2d-x.org/forums/6/topics/36974

I am just so over installing stuff that does not work out of the box, without spending days trying to resolve conflicts of some kind or another. I just want to creating not spend my time tweaking utterly worthless useless rubbish. Instead we have this just follow this easy 13 step plan, maybe just maybe you won’t stuff one of them up, maybe just maybe there won’t be some freaking missing dependancy or some useless conflict with something else.

I will probably never ever buy a SailfishOS or Tizen phone just because the time I’ve wasted trying to get their gao shi development environments to work.

I’ve never ever been able to get a dev environment for Cocos2dx for Android to work properly but I’ve been able to create 12 apps in the apps store with iOS (including Cocos2d) because shit just works out of the box in xcode.

Don’t waste my time trying to config stuff or jump through hoops to get a feaking release build to work.

R.


#15

Hello Regan Russell, I understand you completely. Good people try to help, like our friend Sriram Kumar Bikkina. But unfortunately, what you said is what happens.


#16

Regan, I understand your frustration on setting up cocos2d-x. I myself worked hard on a trail and error basis for almost a week and then succeeded in installing cocos2d-x on a windows machine. I can say that this time was well wasted. I figured out there might be fellas’ like me and wanted to help them to easily setup cocos2d-x. That’s the reason I wrote this guide.

Regan Russell wrote:

Jair Humberto da Silva Filho wrote:
> Hello, How can I find the gcc4-core and gcc4-g++ cygwin packages? I found the others except this two. :confused:
>
Configuring stuff these days is such a nightmare and all the missing pieces to find, conflicts and where do I have to jump through what hoops to get this piece of junk to build…
>
What would be heroic, if someone would build a virtual machine, (VMWare, Virtual PC, Virtual Box, whatever) that had an O/S (any I don’t care but Linux would be legal) and a pre-installed Cocos2dx development environment for Android development.
>
That would be would get kudos by the bucketful from me.
>
I’ve been messing about with SailfishOS SDK, Tizen SDK, and other useless pieces of crap. I am thoroughly sick and tired of installing things that don’t work, require conflicting plugins or are just thoroughly a sick joke. There is no Windows8 installer and the Windows7 installer won’t install on Windows8, the OS-X installer won’t install on the current version of OS-X because it seems to rely on an OS-X version two whole point releases ago. Back to Cocos2dx, Windows Phone8 won’t even build release versions out of the box, how hard can it be to change the freaking drop down from Debug to Release before packaging a build. http://www.cocos2d-x.org/forums/6/topics/36974
>
I am just so over installing stuff that does not work out of the box, without spending days trying to resolve conflicts of some kind or another. I just want to creating not spend my time tweaking utterly worthless useless rubbish. Instead we have this just follow this easy 13 step plan, maybe just maybe you won’t stuff one of them up, maybe just maybe there won’t be some freaking missing dependancy or some useless conflict with something else.
>
I will probably never ever buy a SailfishOS or Tizen phone just because the time I’ve wasted trying to get their gao shi development environments to work.
>
I’ve never ever been able to get a dev environment for Cocos2dx for Android to work properly but I’ve been able to create 12 apps in the apps store with iOS (including Cocos2d) because shit just works out of the box in xcode.
>
Don’t waste my time trying to config stuff or jump through hoops to get a feaking release build to work.
>
R.


#17

I’ve been a paid coder since 1988, so I am a grumpy old fart having a major melt down.

However, here is my experiences with Cocos2d:
iOS

Install xcode, cocos2d, churn out a dozen apps about half are cocos2d apps. Everything just works. I configure nothing, nada, nil, zilch, zip.

Windows Phone
—————
Install Visual Studio, install a version of cocos2d much older than the current one. Build a cocos2d app. Jump through hoops trying to get the release build to work…


Write up something on the wiki about working with the older version for WP8
http://www.cocos2d-x.org/wiki/Windows_Phone_8_Environment_Setup?project_id=cocos2d-x
Audio works in debug, release build - no audio, post on these forums, no help.
Sit down with a Microsoft support Engineer in the local Microsoft building, he couldn’t work it out either. Release a crappy game with no audio - http://www.cocos2d-x.org/forums/21/topics/31696

Download the current version of cocos2d for Windows Phone, build debug, test, works okay, good, now switch to release on the drop down in VS, won’t even build… http://www.cocos2d-x.org/forums/6/topics/36974 I’ve done nothing but change a drop down and within 10 minutes of downloading the latest version I’m giving up on it.

Android
——-
Attempt to mess about with the Android SDK, NDK, and whatever on 3 different platforms (OS-X, Linux, Windows), get annoyed enough to wander off and kick something, each time. Not even to the point of working with Cocos2d.

Sriram Kumar Bikkina wrote:

Regan, I understand your frustration on setting up cocos2d-x. I myself worked hard on a trail and error basis for almost a week and then succeeded in installing cocos2d-x on a windows machine.
So thanks for providing this guide. Damn shame that stuff doesn’t just work and you have to waste a week trying to figure stuff out. Personally, I hate guessing games.

Now, you darn kids git orf my lawn :wink: :wink:

R.


#18

The python package should be included among the cygwin packages, and gcc4-core and gcc4-g*+ should be removed, once gcc-core and gcc-g*+ are mentioned already.

Well, finally I arrived at the twelfth step, but unfortunatelly, the same error Nguyen got, happened to me :confused:

however, this tutorial is great! Congratulations, you was a real warrior discovering everything.


#19

I found the solution for the problem above in http://stackoverflow.com/questions/18162226/program-bash-is-not-found-in-path

But, now, I got the following problem
* Android NDK: Aborting. .Stop.”


#20

@Jair Humberto da Silva: I also did follow the guide in that link, fortunately my problem is solved :D.