Cocos2dx 3.0 Development Environment Construction -- Build an Android project on Eclipse, cocos2dx -- eclipse

Source: Internet
Author: User

Cocos2dx 3.0 Development Environment Construction -- Build an Android project on Eclipse, cocos2dx -- eclipse

I. Preface:

This article mainly introduces some basic content of Cocos2d-x 3.0, and compile our Cocos2d-x project on Eclipse, successfully run Helloworld. After reading this blog, you will know that Cocos2d-x 3.0 has had such a big change, become so simple, environment building, project creation, compilation method is more humane.

II. Environment preparation:

1. Download ADT Bundle (SDK and ADT are bound to Eclipse), or install the ADT plug-in Eclipse.
2. Install JDK, NDK, Ant, and Python, and configure the environment.

3, Cocos2d-x 3.0 download, Environment configuration.

Configure the environment step by step

1) Eclipse preparation. This is mainly a development tool, but it is now officially recommended by android. It is very easy to use with an integrated sdk and adt Eclipse. Here, you can download the data from the Internet. You need to go over the wall to see whether the data can be downloaded from the Internet.

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

2) Android compiling environment requires the use of Andorid_SDK Android_NDK, Ant, and JDK. In addition to JDK installation, You can decompress the green version directly.

We extract the SDK, NDK, and ANT to the same folder and modify the sdk folder named ADT, NDK, and ANT to facilitate future use. After decompression, all files are stored in the D: \ softfile \ android folder.


Configure jdk:

After JDK is installed, you must manually configure environment variables.

1) create a JAVA_HOME variable in the system variable. The variable value is D: \ Program Files \ Java \ jdk1.6.0 _ 14 (enter it according to your installation path)

2) create a new classpath variable with the variable value:.; % JAVA_HOME % \ lib \ tools. jar (note that the previous. Do not forget it)

3) Add the variable value % JAVA_HOME % \ bin; % JAVA_HOME % \ jre \ bin in the path variable (no need to create a new variable) (note that the variable values are separated)

4) log out of the system again and log in again and then "start" --> "run" --> Enter "javac" --> "Enter". If you can print the command properly, the configuration is successful!


Next we will configure other environments. Other environment configurations need to be completed by using python and cocos, so now we will first configure the python and cocos environments.


Python installation and environment Configuration:

Download Python 2.x. Do not download Versions later than python3.0. Otherwise, an error will occur.

You can use the default installation method when installing python. However, after installing python, You need to configure environment variables.

Choose my computer (right-click)> Properties> advanced system Settings> Advanced Tab> environment variables> system variables, and find the Path variable, add the environment variable pointing to Python in the value. The format is [Python installation path]. For example, the environment variable I installed on drive C is added to D: \ Python27;
After the configuration is complete, log out and then log on to the system environment variable to make the configuration take effect.



Next, we want to download the latest version of cocos2d-x, so far the cocos2d-x has been updated to version 3.3, here I download is version 3.0.

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


Environment configuration for NDK, ANT, and SDK:

After the download is complete, decompress it to the disk, open the cocos2d-x folder, find the setup. py file, run, or:

1) Open cmd on the console and enter the root directory of cocos2dx.
2) enter the command: python setup. py, as shown in the running result (note the red box. If you do not configure environment variables such as NDK, you will be asked to enter the path of NDK, SDK, and ant here)

If you do not configure the Android environment now, you just need to press enter all the time, this python script will help us set the environment variables required for cocos2d-x running. Log out and log on again





After configuring these settings, we can view the corresponding environment configuration in the environment variables. cocos automatically configures them for us.


After all this is configured, open CMD and run the cocos command to check whether the entire development environment is successfully set up. If the settings are correct, the following interface will appear:
Here we can see that the cocos. py script can execute four commands. The role of each command is clearly described.

3. Create a project

Now it is time to use the command to create an empty project: Create a project (explained in brackets) in the cmd console, type the example cocos new hello (project name)-pbing. stone. hello (package name)-l cpp (project type)-d E: \ MyCocos \ cocos2dx_workspace (Project Storage path)
For example, if you want to create a cpp project, you can type "cocos new MyGame-p bing. stone. mygame-l cpp-d F: cocos // MyProject. This command will help us create an empty project named MyGame in F:/cocos/MyProject, as shown in:



Run the following command:



After creating a project, you can see the project in the folder:


Iv. Build an Android project using Eclipse

When using Eclipse to build Android, we recommend that you follow these steps:
Go to the Cocos2dx project you created and enter proj. android directory. For example, if a project named MyGame is created under F: cocos // MyProject/, go to MyGame/proj. run the following command in the android directory:
Python build_native.py


The above steps are compiled. After compilation, we can import the proj. android project to our Eclipse.
Use Eclipse to open an existing Android project,



After the project is imported, there will certainly be errors, because our cocos package has not been imported yet, that is, libcocos2dx, which is now a key step, we need to import the android package in the downloaded cocos. Which package is it? Cocos \ cocos2d-x-3.0 \ cocos \ 2d \ platform \ android \ java


Of course, it is not a simple import. We need to copy the java folder to our project, that is, the MyProject we created.

For example, the Java project under MyProject is copied from Cococs2dx, put it in a directory of the project created with the cocos command, and then import it using Eclipse.


After libcocos2dx is imported, the configuration path is:


Then you can right-click-> Run as to directly Run the Android project, no additional configuration (Cocos2d-x 3.0 is so simple ).



The above is how to run our Cocos2d-x project in Eclipse.


An error occurred while setting up the eclipse + Android development environment !!

Build an Android Development Environment

1. Download the Android SDK

Code.google.com/android/download.html

This is the official website. after entering the website, follow the process and select an SDK package suitable for your own platform (Windows) to download.
After downloading, decompress the package and you can use it.

To directly use the SDK tool in the DOS console, you can add the SDK directory to the path environment variable in Windows:
Right-click my computer on the desktop and choose Properties> advanced> environment variables ].
Double-click the Path entry in system variables to add the complete Path of the tools directory in the Android SDK here.

2. Download JDK6

Java.sun.com/javase/downloads/index.jsp

Download and install the Java Development Kit. (I have downloaded and installed this file, and jdk is automatically updated every time)

3. Download Eclipse3.4.1

Www.eclipse.org/downloads/

On the "Eclipse Packages" tab, select "Eclipse Classic3.4.1" to download the package. This is the latest version.

For Eclipse, you can directly decompress the package and use it. (I have myeclipse 6.5)

4. Download the Android ADT plug-in of Eclipse

Install the Eclipse plug-in (ADT)

To download and install the ADT plug-in, follow the steps Google provides to developers:
1. Start Eclipse and select "Help"> "Software Updates"> "Find and Insta ll"
2. In the displayed dialog box, select Search for new features to insta ll and click New"
3. Click "New Remote Site"
4. In the result dialog box, enter a name (for example, Android Plugin) for the remote site and enter
This URL serves as its URL:
Dl-ssl.google.com/android/eclipse/
Click OK.
5. Now you should see that the new site is loaded into the search list (and selected) and click "Finish ".
6. In the subsequent search result dialog box, select "Android Plugin"> "Developer Tools" to check
... The remaining full text>

How to build an Android development environment using eclipse

First download an android sdk, and then install the simulators of various android versions online. It takes a lot of time. I remember that I spent a whole night (my network speed is slow). After the installation, I can create a simulator. Of course, this can only be an independent running simulator that has not been integrated into the IDE.

Secondly, download ADT (Android Development Tools) PLUG-IN. The adt plug-IN can be integrated into Eclipse or MyEclipse. you can install it online or independently download ADT, then integrated into the IDE. In this way, you can use MyEclipse to develop android applications.

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.