Cocos2d-x's Android Build Environment (second article) [Version number: cocos2d-x-3.1.1]

Source: Internet
Author: User


Learning Journey-----Environment building based on the Android NDK

工欲善其事 its prerequisite, the following describes the setup of the Eclipse SDK NDK Cygwin CDT integrated development environment.

1, Android development environment to build

Android development environment is not the focus of construction, I believe that the article is a lot of people have been building success, here casually outline of the said.

1) Download JDK

2) Download Eclipse

3) Download Android SDK

4) Start Eclipse, install ADT

2. Download and install Android NDK

NDK Download stamp here: Https://dl.google.com/android/ndk/android-ndk-r9d-windows-x86.zip

3. Download and install Cygwin

because the NDK compiles code with make and GCC, you must first build a Linux environment. Cygwin is a UNIX emulation environment that executes on a Windows platform and is useful for learning unix/linux operating environments, or porting applications from UNIX to Windows.

With it, you can use the NDK to compile C, C + + code without installing Linux. Here's a step-by-step installation of Cygwin.

(Forgotten when installing)

First of all. You'll have to run to http://www.cygwin.com . Download setup.exe

1. Then double-click Execute, and after execution you will see the Installation Wizard interface:

2. Click Next

At this point you choose how to install:

1) Install from the Internet: Download directly from the Internet and install it immediately (after installation, the downloaded installation files are not deleted.) But is still retained. For next installation).

2) Download without installing: Just download the installation file locally. However, it is not installed temporarily.

3) Install from local Directory: Do not download the installation file, directly from a folder containing the installation files locally.

3. Select the first item and click Next:

4, select the folder to install, note, it is best not to put in a folder with Chinese and white space, it seems to cause installation problems, other options do not change. Then click Next:

5, the previous step is to choose to install Cygwin folder, this is to choose the folder where you download the installation package, the default is that you execute Setup.exe directory. Direct point to the next step is:

6, at this time you have three kinds of connection options:

1) Direct Connection: Connect directly.

2) Use IE5 Settings: Connect using the connection parameters setting of IE.

3) Use HTTP/FTP Proxy: Connect using HTTP or FTP Proxy server (you need to enter the server address, port number).

Users can choose according to the actual situation of their network connection, under normal circumstances, choose the first type, that is, direct connection mode. Then click "Next",

7, this is the choice to download the website, I use is http://mirrors.kernel.org, the speed feeling is quite fast. Select After point next

8. Download the list of installation packages at this time

9, search can enter the name of the package you want to download. You can filter out the packages you want to download at high speed.

The four radio buttons are the style of selecting the tree below, and by default you don't have to move. View default is category, it is recommended to change to full display all packages and then check, some of the province's packages are hidden away. The check box in the lower left corner is whether to hide expired packages. Default tick. You don't have to worry about it. Download the package we want to install below. To avoid all downloads, the following packages are listed for the development ndk: autoconf2.1, automake1.10, Binutils, Gcc-core, gcc-g++, Gcc4-core, gcc4-g++, GDB, Pcre, Pcre-devel, Gawk, make a total of 12 packages

10. Then start choosing to install these packages. Click Skip. Turn it into a digital version number format, to make sure that the bin item becomes a fork, and that the SRC entry is the source code, this is not required.

11, the following test Cygwin is not already installed.

Execute Cygwin, in the popup command line form input: Cygcheck-c cygwin command, will print out the current Cygwin version number and execution status, assuming the status is OK. The Cygwin performs normally.

Then enter gcc–version,g++--version,make–version,gdb–version to test (or, input make-v and gcc-v), assuming that the version number information and some descriptive narrative information, I'm glad to tell you, Your Cygwin is installed!

4. Configure NDK Environment variables

1, first find Cygwin installation directory, find a home\< your username>\.bash_profile file, my is: E:\cygwin\home\Administrator\.bash_profile, ( Note: My home directory does not have the following gods and horses when I install it. Workaround: First open the environment variable. Delete the home variable inside the user variable, create a directory named Administrator in the E:\cygwin\home directory (username), and then E:\cygwin\etc\skel\.bash_ Profile is copied to this directory).

2. Open the Bash_profile file. Add ndk=/cygdrive/< your drive letter >/<android NDK folder > For example: NDK=/CYGDRIVE/E/ANDROID-NDK-R5

Export NDK

The name of the NDK is casually taken, for the convenience of later use. Pick a short name and save it.

3, open the Cygwin. Enter the CD $NDK, assuming the output of the/CYGDRIVE/E/ANDROID-NDK-R5 information configured above, indicates that the setting environment variable was successful.

5. Use the NDK to compile the program

1, now we use the installed NDK to compile a simple program, we choose the NDK's own sample Hello-jni, I am located in E:\android-ndk-r5\samples\hello-jni (depending on your detailed installation location),

2, the implementation of Cygwin. Enter the command Cd/cygdrive/e/android-ndk-r5/samples/hello-jni and go to the E:\android-ndk-r5\samples\hello-jni folder.

3, input $ndk/ndk-build, after the successful operation, it will voluntarily generate a Libs folder, the compiled generated. so file inside.

($NDK is to invoke the environment variables we configured earlier, Ndk-build is the compiler that calls the NDK)

4, at this time to hello-jni the Libs folder to see if there is no generated. so file, fake. Your NDK is doing fine!

6. Integrated C/D + + development environment in eclipse

1, install the eclipse of A/C + + Environment plug-in: CDT, here choose Online Installation.

First log in to http://www.eclipse.org/cdt/downloads.php to find the online installation address of the CDT plugin for your eclipse version number.

2. Then click the Help menu to find the Install New software menu

3, click AddButton. Fill in the address you have taken. After the plugin list, select All. Then select next to complete the installation

4. After the installation is complete, right-click the new project in Eclispe. Assuming that a C + + project appears, your CDT plugin is installed successfully.

7. Configuring the C + + compiler

1, open Eclipse, import the NDK Hello-jni sample, right click on the project name, click Properties, pop up the configuration interface, then click Builders, pop Up the project's compilation tool list. Then click New to add a compiler. The join screen appears after clicking. Select program and click OK

2, there is a join interface. First give the compiler a name for the configuration. such as: C_builder

Set location to < you cygwin installation path >\bin\bash.exe program, for example: E:\cygwin\bin\bash.exe. Set working directory to < your Cygwin installation path >\bin folder, for example: E:\cygwin\bin

Set arguments to

--login-c "cd/cygdrive/i/javaworkspace/blog/ndk_02 && $NDK/ndk-build"

In the above configuration/cygdrive/i/javaworkspace/blog/ndk_02 is the folder of the program you are currently compiling, $NDK is the environment variable of the NDK that was previously configured, these two are configured according to your detailed installation folder, and the others do not change. Arguments this number of parameters is actually the Bash.exe command-line program to pass the number of references. Go to the program folder you want to compile, and then execute the ndk-build compilation program

3. Then switch to the Refresh tab and give the refresh resources upon completion the bait.

4. Then switch to the Build Options tab and tick the last three items

5, then click Specify Resourcesbutton, select the Resource folder. Tick your project folder to

6, finally click Finish, click OK all the way to save the previous configuration, note: Assume that you configure the compiler below the other compilers. Remember to be sure to point UpButton and put it first. Otherwise, the compilation of C code is later than the compilation of Java code. Will cause your C code to compile two times ability to see the latest changes

7, this way down must be very tired, now congratulations again. Compile configuration is also configured, now to test whether it is enough to self-compile, open the Project Jni folder in the Hello-jni.c file to the hint Hello from jni! to other text: such as: Hello. My name is Alex, and then execute your program in the emulator. Let's say the simulator shows you the latest changes in the text. So congratulations!

You have all the configuration success!

The article references http://yueguc.iteye.com/blog/946724


Cocos2d-x's Android Build Environment (second article) [Version number: cocos2d-x-3.1.1]

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.