"Go" cocos2d-x Windows Development Environment configuration

Source: Internet
Author: User

Statement: This tutorial in reference to the following blog post, and after their own groping after the actual operation, the tutorial is my original, due to the upgrade of the Cocos2d-x has a number of changes, the current blog has no cocos2d-x 2.2.1 The latest version of the Build Android cross-compilation environment, So I studied these days, and now will be specific building methods to share, but also to learn cocos2d-x to make a note. Reference post: http://www.cnblogs.com/lhming/archive/2012/06/27/2566460.html
Http://www.cnblogs.com/lhming/archive/2012/06/27/2566467.html
Http://www.douban.com/note/229610750/
Http://www.cnblogs.com/dekins/archive/2012/08/22/2650131.html This article address: http://blog.csdn.net/sttyytw/article/details /17005263 If reproduced, please specify the source! This paper sets up the environmental system: Win7 64-bit flagship version of the original
Software: Only half-bare metal with system installed

As long as you follow the steps of the patient operation, the environment will not create a few inexplicable mistakes

Ready to download the software (for convenience, the software installation package please put in a folder)

Please download first, but do not install, step by step to

1, cocos2d-x2.2.1 November 19, 2013 update


Cocos2d-x Game Engine development environment, we all know.

: (This needless to say, build cocos2d-x platform will not know where the code? OK, or stick it on)

Http://www.cocos2d-x.org/download

2, VisualStudio 2012


Cocos2d-x Required IDE compilation environment, online casually, here to provide a

: http://pan.baidu.com/share/link?shareid=90168&uk=2769186556

Key: YKCW6-BPFPF-BT8C9-7DCTH-QXGWC

3. Python


The cocos2d-x2.0 version uses Python scripts to create the project later, so the Python environment is required

: http://www.python.org/download/


Note: please download the python2.7.6 64-bit version, not the next 3.3 version

These are the software needed to build the Cocos2d-x compilation environment, followed by the software required for Android cross-compiling


4. java


Java environment is necessary, this can be downloaded on the official website, note to choose the 64-bit version

: http://www.java.com/zh_CN/download/manual.jsp


5. Android SDK


This is the IDE environment that Android cross-compiling must have, including eclipse

: http://developer.android.com/sdk/index.html


6. Android NDK


When Android cross-compiling, the interpretation and compilation tool for C + + code

: http://developer.android.com/tools/sdk/ndk/index.html


7, Cygwin


Explanation of the Cocos2d-x native C + + code compilation Tool

: http://cygwin.com/install.html


8, EditPlus


This is a text editing software, convenient for us to edit after the sh file

: http://www.pc6.com/softview/SoftView_36775.html


Note: When Linux files such as sh are opened with Windows Notepad, the entered return format differs from the Linux return format, causing errors.

This software is recommended for everyone to use, we can choose their own

Now that the software we need is ready, we can start building the environment.

———————————————————————————————————

1, installation VisualStudio2012

Unzip the Vs2012_ult_chs.iso file, install it, and be mad about the Setup program .....

Like this programming environment is best installed in the system disk, lest after a variety of inexplicable errors. Waited for some time, finally installed finished.

2. Build cocos2d-x Windows compilation environment with VisualStudio

Put the downloaded cocos2d-x-2.2.1 in the English path, note that the English path does not have spaces

Example: My directory configuration D:\study\cocos2d-x\cocos2d-x-2.2.1

Locate the visual Studio2012. sln file in the cocos2d-x-2.2.1 directory, open

Wait for Visual Studio to load the solution

Right-click on the solution, then point to build Solution, or press F7, wait for vs compile to generate local obj

The first compilation will be slow, wait patiently

Waited for nearly 10 minutes, finally compiled, we come to taste the early adopters, try to run Hellocpp, see the familiar HelloWorld interface

Right-click on the Hellocpp project and select Debug--Start a new instance

Then the program starts to compile automatically, and if you're lucky, you should see the HelloWorld interface of Ox X.

Here I have a small problem, because it is a new system, not installed graphics drivers, so the compile prompt OpenGL version is too low, this time only need to use the Driver Wizard or similar driver software to update their graphics driver is no problem.

3. Create your own HelloWorld project

The next step is to create your own cocos2d-x HelloWorld project, which is the beginning of all game authoring. Well, then we're going to use the Python environment. Install the PYTHON-2.7.6.AMD64 that we have downloaded and select the default path.

After installation, we then use the Python command to create our own Cocos2d-x project.

First, you need to set up a python system environment, because it is the default installation, so Python installation path is C:\Python27\, you can manually at the beginning and the computer (right click above), properties, advanced system settings, Set the path path in the environment variable and add the Python installation directory, but personally I prefer to change the environment variable with the cmd command. (Incidentally, you can use a batch to write all of the settings in this article that involve environment variables with the WMIC command.) )

Okay, win+r run cmd, enter the following command

WMIC environment where "name= ' path ' and username= ' <system> '" Set variablevalue= "%path%; C:\Python27 "

Note that the above is named one line

Then reopen cmd, enter Python, and find that Python is not an internal command, and then enter the command:

Echo%path%

Found no Python directory we set up just now, what's going on? In fact, here is the environment variable is not updated for the sake of, we set up again after, or to enter the start-up computer (in the right button above)--advanced system settings, such as environment variables, and then do not change, direct point OK, then back to cmd view path directory, This only found that we have set up the Python directory. Some children's shoes will certainly ask, since still want to enter the environment variable setting interface, why I do not directly in the inside set not on the line, but also so troublesome to do? This is the most direct.

But I do not like the path that strip of input box, dragged over the past, and the semicolon what the path of writing error-prone, so it is recommended that you take more than the form of the command is better.

OK, let's try our configuration correctly. Enter the command:

Python-?

Then Balabala ... A bunch of them, which means that our Python configuration is ready.

Next, create the project using Python. Enter the cocos2d-x-2.2.1 directory of Tools->project-creator, you can see there is a Create_ project.py script, if you are interested in child shoes can right-click in the IDE open to see, from which you can intercept how the script is used

All right, let's get this script to work.

In the Project-creator directory, press and hold shift+ right mouse button, select here to open the Command window, enter the command:

Python create_project.py-project helloworld-package org. Helloworld.game-language CPP

And wait for the result.

As you can see, our project has been created, where HelloWorld is the name of the project we entered in the command, that is, under the Cocos2d-x-2.2.1->projects folder created our project, the name is HelloWorld, The Proj.android folder under the HelloWorld folder is the Android project that we need to compile later, and the org.HelloWorld.game behind the Create command is the identity name of the Android apk, and you can follow the "xxx.xxx.xxx" The format itself is named.

Here I wrote a bat batch, you can put in the Project-creator directory, later can be very convenient to create the project

Right-click on the Project-creator directory to create a text document, open, copy the following, then click Save, change the file suffix named bat

-----------------------------------------------------------------------------------------

@echo off
: Label1
@cls
Echo Welcome to create Cocos2d-x project with Python
set/p project= Please enter the name of the project you want to create:
set/p aid= Please enter the identity name of the Android version package you need to create:
echo the project you entered is named%project%
echo the Android version package you entered is identified with the name%aid%
Does echo confirm the creation of the project?
CHOICE/C 123/m "Confirm please press 1, cancel please press 2, or exit please press 3. "
Echo%errorlevel%
If%errorlevel%==1 Goto Label2
If%errorlevel%==2 Goto Label1
If%errorlevel%==3 Goto LABEL3
: Label2
Echo is creating the project ...
Python create_project.py-project%project%-package%aid%-language CPP
: Label3
Pause

-----------------------------------------------------------------------------------------

Note Just copy the above purple section.

Back to Visual Studio2012, right-click on the solution, point to add Existing project

Then find helloworld.vcxproj under this directory (COCOS2D-X-2.2.1\PROJECTS\HELLOWORLD\PROJ.WIN32)

Click to open

We can see that our heloworld has been added to our project. Well, wait for what, compile it. Here, we can set HelloWorld as the startup project, so that you can easily click on the "Local Windows Debugger" for debugging every time you debug, instead of starting a new instance every time. You can find the "Set as Startup Project" column by right-clicking on the HelloWorld.

After the setup is complete, we'll find that our HelloWorld is bold, OK, run for a try
Click Local Windows Debugger, pop-up window, select no longer Show this dialog box, then click Yes

Wait for compile, then will output HelloWorld window, this time is "small bottle" of, hehe!

Well, we've already created our own project!

Next to configure the Android cross-compilation environment cocos2d-x under Win7

4. Installing Java, setting up the Java environment


Android environment is built without Java this thing, select the default path is installed, you can use the WMIC command to add Java environment variables to the system, Win+r run cmd, enter the following three commands

WMIC environment Create Name= "Java_home", username= "<system>", variablevalue= "C:\Program files\java\jre7"

Above is a row
WMIC environment Create Name= "CLASSPATH", username= "<system>", variablevalue= ";%java_home%\lib\;"

Above is a row
WMIC environment where "name= ' path ' and username= ' <system> '" Set variablevalue= "%path%; C:\Program Files\java\jre7\bin "

Above is a row

Then go to the System environment variable settings interface update, restart CMD, try to enter Java, as long as it does not appear "Java is not internal command or external command" and so on, it means that you set the success.

5. Install Cygwin and configure Android NDK

Run the downloaded Cygwin-setup-x86_64.exe and see the following installation interface

Click Next

Go on

The default path installation, and then choose to download the saved path, this can be configured on their own, the best to do after the installation of a backup, so as to avoid the need to install again to download, the domestic speed download or compare the egg pain ~~~~~

Default selection, Next

Select the first site

Here everybody notice, must be red box marked out of click, become install

Click Next, long wait for download ~~~~~~

Finally the installation is complete, let's open it up and try it.

The first point of opening the Cygwin directory will generate a folder with the name of the system login under the C:\cygwin64\home file.


Then we found the EditPlus software in the software we downloaded, and by default, we can open any text file with EditPlus software.

Now, the Android NDK that we downloaded is android-ndk-r9b-windows-x86_64.zip to the English path, and this path will be written to the Cygwin. Bash_profile configuration file, OK, My decompression path is: D:\study\android\IDE\
Note: The path cannot have spaces, all in English

You find the. bash_profile file under the folder named under the system login account under the C:\cygwin64\home file, right-click, open with EditPlus software, enter carriage return at the end, and enter the following statement:

ndk_root=/cygdrive/d/study/android/ide/android-ndk-r9b

Export Ndk_root

The above is two lines

Then click Save, Close. Here Cygwin refers to the local disk, D is the D drive, followed by the NDK path, you fill in the path of your own files, note the Windows path "\" and Cygwin "/" difference. By the way, directories are always written to a folder with Ndk-build.cmd files.

Then use EditPlus to open the BASH.BASHRC file under the C:\cygwin64\etc folder, enter a carriage return at the end, enter your own Cocos2d-x project's folder path (remember the HelloWorld project we created earlier?). Note that this step is not necessary, and the complete function is not to enter the full path to jump to your project folder each time you open cygwin. OK, my path is configured as:

CD d:/study/cocos2d-x/cocos2d-x-2.2.1/projects/helloworld/proj.android

Above is a row

You can change the path according to their own, in the future when the new project also remember to change their own compilation path. It is also important to note the difference between "\" and "/" in Windows path in Cygwin.

Restart Cygwin, you can see that the current path has become the path we set

Well, enter the LS command and you'll find a build_native.sh file that we need to compile with the NDK.

Then enter the following command:
./build_native.sh

Above is a row

If it goes well (there is no problem when you follow the steps carefully), you can see that our NDK is starting to work hard to compile some native C + + code for Cocos2d-x ~~~~~ is a long wait.

Once the compilation is complete, you can exit Cygwin.

This is the final interface after the completion, if you can see this interface, then represent this step successfully completed.

6. Install the Android SDK and configure the Android Eclipse compilation environment

Find our download Adt-bundle-windows-x86_64-20131030.zip, decompression, the path can be configured by their own, or pay attention to the English path, no space can be.

Then run eclipse under Adt-bundle-windows-x86_64-20131030\eclipse (ADT comes with the Eclipse compilation environment), select the project folder, where you can configure

Then turn off the instruction page and go to the main interface. Click Configure SDK in the main interface

Then you can choose the Android SDK version as required, here I choose to download Android (API 8), and then select Install

Slowly wait for the download installation to finish.

Next Configure the Android VDM

Then choose Devicedefinitions, casually choose a create, as if the current VDM does not support the high version of OpenGL, so I will use the Bluestacks simulator to debug, here just build apk

7. Compiling Android Project

Well, all of our environments have been built, and before we import our project into Eclipse, we need to cocos2d-x-2.2.1\cocos2dx\platform\android\java\ The Org folder under SRC is copied to our project, which is COCOS2D-X-2.2.1\PROJECTS\HELLOWORLD\PROJ.ANDROID\SRC, because the Android package name we created earlier is also an org. So there will be coverage options, please select Merge overlay to

(Is it not every time that you compile an Android project to copy this package over?) In fact, it is not necessary, this is put at the end of the article to discuss)

Next, go back to the Eclipse environment and import the project

Note When you select the path, write to the HelloWorld folder.

After the project is imported, right-click on the project HelloWorld and select Properties

Select Builders, click New

Select Program

And then, in the next interface,

Name field input: Native_builder

Location Bar Input: C:\cygwin64\bin\bash.exe

Arguments column input:--login-c "cd/cygdrive/d/study/android/ide/android-ndk-r9b && make App=helloworld"

Above is a row

Arguments column, login before there are two "-" symbol, the middle of the directory settings refer to the previous tutorial in the Ndk_root path settings, the following HelloWorld for the creation of the project name, which is based on the project name you created.

(Hint: If you are not installing by default path, select the browse File System to find the relevant path)

Select OK, select Native_builder, and adjust it to the top

Then select the C + + Build->environment->add

Next, enter path in the Name field and enter C:\cygwin64\bin in the Value field.

Then select the Libraries bar in the Java Build path and delete the Android dependencies and Android Private Libraries two library

(To illustrate, we've merged Cygwin's compilation environment into Eclipse, and Eclipse uses Cygwin and calls Cygwin bash and make to build our Android program through the NDK, So every time you import a new project to reconfigure the above steps, this is very important, if the configuration is not correct, will lead to a lot of inexplicable error, the most typical mistake is to find out what bash command what the ~ ~ ~ ~)

OK, now we can build the apk file, select your project in the main interface, then select Run->run as->android on the command bar application

If the above steps are set according to the tutorial, you will be able to generate APK, the apk is stored in the Proj.android->bin folder

Put the APK on your real machine and test IT!!!!!

The above compilation environment is configured to end.

——————————————————————————————————

In-depth discussion of the question: Do you want to copy the Org folder under COCOS2D-X-2.2.1\COCOS2DX\PLATFORM\ANDROID\JAVA\SRC to our project every time before compiling the Android project?

In fact, everyone can find that every time we execute./build_ Native.sh, the contents of the resource in the Proj.android folder are copied to the assets folder, so we can modify the sh file a little bit to eliminate the need to copy the local compilation library once every time we create the project.

Method:

1. Found under C:\cygwin64\home\ "own username" \ folder. Bash_profile

2. Open the editor with EditPlus

3, enter the end of the file, add the following path settings

cocos2dx_dir=/cygdrive/d/study/cocos2d-x/cocos2d-x-2.2.1

Export Cocos2dx_dir

The above is two lines

We then found the native build_native.sh in the \cocos2d-x-2.2.1\template\multi-platform-cpp\proj.android directory, and we modified it with the EditPlus open.

In line 36 to find this sentence, this sentence is to judge the path of Ndk_root

We add the same statement later, just replace the ndk_root with the directory we set, which is Cocos2dx_dir

Then continue backwards and join in line 50

echo "Cocos2dx_dir = $COCOS 2dx_dir"

And then we found this statement in the back.

Hey!!!! Everybody see out, this sentence is equivalent to copy file, OK, we follow gourd painting scoop ~ ~ ~

That is, add the following statement to the back:

For file in "$COCOS 2dx_dir"/cocos2dx/platform/android/java/src/*
Do
If [-D "$file"]; Then
CP-RF "$file" "$APP _android_root"/src
Fi
If [-F "$file"]; Then
CP "$file" "$APP _android_root"/src
Fi
Done

OK, the file has been modified, we remember to save Oh!

After this modification, when you re-create the project, the Cocos2d-x Python script will copy the contents of the Template\multi-platform-cpp folder slightly (mainly the modification of the project name) and directly into our project. So we can use the modified file, haha!

———————————————————————————————————

This is the end of the tutorial, if you have any questions about this tutorial, or if there are any errors, please point out!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.