Cocos2d-2.0-x-2.0.3 multi-platform environment construction (Android, Win32)

Source: Internet
Author: User
Cocos2d-2.0-x-2.0.3 multi-platform environment construction (Android, Win32)

Began to contact the cocos2d-x environment set up, there are also a lot of online tutorials, but each is always with their own set up so a little different, not comprehensive, the result is the failure to build... Here I will share my own experiences to benefit others.

Android:

First, let's talk about the environment used. Because it's a new configuration recently, we use a newer version.

1. First, the official Android SDK, ndk, and install the API as needed
Installer_r20.0.3-windows.exe
Android-ndk-r8b-windows.zip

2. The latest JDK
Jdk-7u7-windows-x64.exe

3. The latest eclipse
Eclipse-SDK-4.2.1-win32-x86_64.zip

4. The latest cygwin

5. Of course there is cocos2d-x engine itself.
Cocos2d-2.0-x-2.0.3

Download all of the above and start installation. My system is Windows 7.
1. It is best to install the SDK and ndk here. Just find a place to decompress it.
But remember to configure the corresponding system environment variables.
Specifically: Right-click my computer --- properties --- advanced system settings --- advanced --- Environment Variables
Find the path in the system variable and add a location similar to this
; G: \ Android-SDK \ tools; G: \ Android \ android-ndk-r8b
Use the; interval between addresses, and then enter the SDK's Tools Folder respectively. The ndk's root directory is two locations.
The SDK can only download the required APIs,
Do not forget to configure the AVD simulator environment in the SDK.

2. JDK has nothing to say, but remember to add environment variables to the path. people on this earth will not talk much about it.

3. Decompress eclipse and find a place to put it
If you are not familiar with English, you can use the Babel project to describe the eclipse interface.
Here is an eclipse online installation address.

Http://eclipse.org/babel/downloads.php

Indigo Helios Galileo corresponds to the eclipse version you downloaded.

Then install ADT and CDT two Eclipse plug-ins. You can also install them online.

4. Install cygwin in the latest version.
In fact, you do not need to install the complete cygwin for Android development. However, it is recommended that you install the cygwin for Android development,
You can use the download function of steup.exe to download the complete package for later reinstallation. In addition, many people do not know about the installation.Program,
Resumable upload is possible, as long as it is the same as the previous settings, and do not need to change the path, it is the same as before to re-upload the resumable upload, so it is completely possible
Complete

After the installation, you can run gcc-V, make-V, and other commands to check whether the installation is successful.
Didn't we press ndk before? Now we need to configure ndk and cygwin together.
First, go to the \ cygwin \ home \ System USERNAME \ directory \
Open file. bash_profile
Add at the end (example)

Ndk_root =/cygdrive/G/Android/android-ndk-r8b.
Export ndk_root
 
Ndk_root is actually the path for accessing the ndk folder from cygwin.
Cygdrive is a very interesting directory in cygwin.
/Cygdrive/G/means that we are accessing the G drive letter. Now you know how to access the file path in the hard disk from cygwin.

Note that this file is in UNIX format, not in windows, so press enter and spaces are different. Therefore, do not use TXT to modify the file.
I used vs2010 to do this. (I used it for development under Win32)

5, extract the compressed package of the cocos2d-x
This is troublesome for development. A friend who has used cocos2d may want to copy a file and create a project or something outside the engine. This is not the case here.
First find the create-android-project.bat script, we need to use it to create Eclipse project, automatic, instead of easy problems it
First modify the content: (there is an example in the file)
Search for the SET _ cygbin = variable. Enter the binfile directory in cygwin.
Search for SET _ androidtools = and change to your Android-SDK tools directory.
Search for SET _ ndkroot = change to the root directory of ndk

Save

Double-click the bat button and the Creation Interface will pop up. Here we will enter the package name and project name of the project and select the API version to use. I will not elaborate on it here.
Then it will generate a project name folder in the root directory of the cocos2d-x, this is our android project, there are 3 folders classes, proj. Android,
Resources

In this case, we use the cygwin shortcut to enter cygwin, and run the CD command to enter the proj. Android directory in the newly created Project.
Then there is a build_native.sh file under this directory. We need to run the./build_native.sh command and then we will see the information for starting compilation,
This step is to compile all the C ++ files in the project and generate the. So file to link to the Eclipse project.
After compilation, you can open eclipse and import the Eclipse project in the proj. Android directory.

The project generated in this version lacksCodeThe solution here is to find the Directory
Cocos2d-2.0-x-2.0.3 \ cocos2dx \ platform \ Android \ Java \ SRC
By the way, there is such a missing package code in the engine, copy it to the new project to replace a small part.

It's not over yet. Your project is still reporting an error. Right-click the project,
Find the android tools --- fix project properties option and the Java compiler is automatically configured.

Right-click the project --- properties --- Java compiler. There is an option in it that is consistent with the compilation level. Here, 1.6 is selected, and 5 or 7 is not supported,
This is a bug, that is, the flag for function overloading. It will not be available at 1.6, but when I select 1.7, I find other errors will be reported for the project, so everyone has only 1.6 options left.

At this point, there should be no errors in the project, and then you can run it. If AVD is not configured here, set the AVD simulator first.
Then you will find that the simulator will go wrong, don't be nervous, this is generally because the simulator does not support the new cocos2d-x 2.0 engine OpenGL ES 2.0 API caused
But we can find the generated APK installation package from the bin directory of the project, we can put it in the real machine to install, then we can see the cocos2d-x
Consistent Hello World Interface


Vs2010: no difference in project configuration in 2008
Select Run build-win32.bat this script will compile the entire project
Find several JS scripts in the directory cocos2d-2.0-x-2.0.3 \ template \ msvc
Execute this script installwizardforvs2010.js so you can install the cocos2d-x template to vs2010.
Then we can click the cocos2d-win32.vc2010.sln, and then we can open the cocos2d-x project,
We can see that there are a lot of projects in the solution catalog, these are cocos2d-x engines and examples
Then we directly create a project in this solution, choose to use the template of the cocos2d-x, and then set the new project as a startup Item,
Start now. Now we can see the familiar Hello World interface.

Here broken read, vs2010 directly write cocos2d-x code is simply a kind of torture, no syntax prompt, keyword highlighted, nothing... All are black,
It's hard to write... Therefore, we recommend that you install a visual plugin x plug-in to improve the above problems.

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.