COCOS2DX 3.0 Development Environment build an Android project on--eclipse

Source: Internet
Author: User

First, preface:

This article mainly introduces some basic content of Cocos2d-x 3.0, and compiles our cocos2d-x project on Eclipse to successfully run the HelloWorld. After reading this blog, you will know that Cocos2d-x 3.0 unexpectedly happened so much change, become so simple, environment construction, project creation, compile the way more humane.

Second, the Environment preparation:

1. Download the ADT Bundle (Eclipse bundles the SDK and ADT), or Eclipse installs the ADT plugin.
2. Install the JDK, NDK, Ant, Python, and then configure the environment.

3,cocos2d-x 3.0 download, environment configuration.

Now step-by-step to configure the environment

1)Eclipse Preparation, this is primarily a development tool, but now Android is officially recommended, an integrated SDK and ADT Eclipse, very useful. Here is mainly in the network to download the good, as to browse the network can access the download on the wall you turn.

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

2) Android compilation environment needs to use ANDORID_SDK android_ndk, Ant, JDK, which in addition to the JDK need to install, the other is the green version of the direct decompression.

We extracted the SDK, NDK, and ant into the same folder and modified the SDK folder named Adt,ndk to Ndk,ant for Ant, which is for easy use later. I unpacked the files and placed them under the D:\softfile\android folder.


To configure the JDK:

After the JDK has been installed, you need to manually configure the environment variables

1) Create a new java_home variable in the system variable, the value of the variable is: D:\Program files\java\jdk1.6.0_14 (fill in according to your own installation path)

2) New CLASSPATH variable, variable value is:.; %java_home%\lib;%java_home%\lib\tools.jar (Note the previous.) Don't forget it)

3) Add the variable value in the path variable (existing without new):%java_home%\bin;%java_home%\jre\bin (Note the ";" between the variable values) Separated

4) Re-log off the system and re-login after "Start"-"Run"-input "Javac"-"enter", if you can print the usage instructions successfully configured!


The next step is to configure the other environment, and other environment configurations need to be done with Python and cocos, so let's configure the Python and Cocos environments first.


Python Installation and Environment configuration:

You need to download the Python 2.X version here. Do not download the version above python3.0, otherwise the operation will be wrong.

Python is installed using the default installation method, but after installation we need to configure environment variables

Locate the path variable in the system variable, environment variable, advanced system settings, properties, and so on my computer (right-click), and add an environment variable that points to Python in its value. The format is [python installation path]; For example I installed in C drive My environment variable is added as D:\Python27;
After configuration, remember to log off and re-login to the system environment variables will not take effect



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

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


NDK, ANT, SDK environment configuration:

After the download is complete, we unzip to disk and open the Cocos2d-x folder to find the setup.py file, run it, or do the following:

1) Open the console cmd and enter the root directory of the COCOS2DX
2) Input command: Python setup.py, run the result as shown (note the Red box section, if you do not configure the NDK and other environment variables, then here will let you enter the path of ndk,sdk,ant)

If you don't configure the Android environment now, so you just have to go straight in, this Python script will help us set the environment variables required for the cocos2d-x to run. Logout, re-login





After configuring these we can see the environment variable in the corresponding environment configuration, Cocos automatically configured for us.


After configuring it all, we open CMD to run the Cocos command, to check whether the entire development environment is successful, if the settings are not a problem, the following interface will appear
Here we can see that the cocos.py script can execute 4 commands, and the role of each command has been clearly explained.

Iii. Creation of the project

now it's time to use the command to create an empty project:Create project (interpreted in parentheses) in console cmd Type 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, we want to create a CPP project, and then I 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 this command as follows:



After you create a project, you can see the items under the folder:


Iv. Eclipse to build Android projects

When we use Eclipse to build Android, we recommend that you follow these steps:
Go to the COCOS2DX project you created, enter the Proj.android directory, for example, create a project called Mygame under f:cocos//myproject/, and go to the Mygame/proj.android directory and execute the following command:
Python build_native.py


The above steps are compiled, and after compiling, we can import the Proj.android project into our eclipse.
Then use Eclipse to open an existing Android project,



After importing the project, there must be a mistake, because now our Cocos package has not been imported, that is, libcocos2dx, now is also a key step, we need to download the Cocos inside the Android package to import it, that is the package it? Cocos\cocos2d-x-3.0\cocos\2d\platform\android\java


Of course, it is not easy to import, we need to copy the Java folder under our project, that is, we created the MyProject

If the Java project under MyProject is copied from COCOCS2DX, put it in a directory with the project that we created with the Cocos command, and then import it with Eclipse.


after importing LIBCOCOS2DX, it is the configuration path:


You can then right-click->run as to run the Android project directly without additional configuration (Cocos2d-x 3.0 is simple).



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

COCOS2DX 3.0 Development Environment build an Android project on--eclipse

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.