Windows cocos2d-x Android Packaging

Source: Internet
Author: User
This article is 51cto bhubhu original. For reprinted, please mark the original author and source to show respect!

Author: bhubhu

Original article: http://taodym.blog.51cto.com/3032223/1112160

1. Download and install Android ndk

My application's ndk version is r8b

Before that, we need to know what Android ndk is. Just draw a picture from the gourd tree. You may die very badly. If you make a small mistake, you will not be able to match it.

Ndk is a collection of tools. Ndk provides a series of tools to help developers quickly develop C (or C ++) dynamic libraries, and can automatically package so and Java applications into APK together. These tools are of great help to developers.
Ndk integrates with the cross compiler and provides the MK file isolation platform, CPU, API, and other differences, developers can create so simply by modifying the MK file (indicating "which files need to be compiled" and "Compilation feature requirements. Ndk can automatically package so and Java applications, greatly reducing developers' packaging work. Ndk provides a stable and functional API header file statement. Google explicitly states that this API is stable and supports the currently released API in all subsequent versions. From the ndk version, we can see that these Apis support very limited functions, including: C standard library (libc), standard Math Library (libm), and compression library (libz), log Library (liblog ).


2. Install cygwin

Because make and GCC must be used to compile the ndk code, you must first set up a Linux scene. cygwin is a UNIX imitation scene running on the Windows platform, it is very effective for studying the Unix/Linux operating scene, or porting the application method from UNIX to Windows. Through this process, you can use ndk to compile C and C ++ code without installing Linux.


First of all, you have to go to the http://www.cygwin.com to download setup.exe

1. Double-click it to run the command. After running the command, you will see the installation lead interface:

2. click Next.

In this case, you can choose the installation style format:

1) install Internet: directly load data from the Internet and install it immediately (after the installation is complete, the downloaded installation file will not be deleted, but will still be saved for next installation ).

2) download without installing: only downloads the installation file to the local device, but does not install it temporarily.

3) install local directory: Install the local directory directly from a local directory without downloading the installation file.



3. Select the first item and click Next:

4. Select the directory to be installed and pay attention to it. It is best not to place it in the directory with Chinese characters and spaces. It seems that the installation problem may occur, and other options will not change. Next, click Next:

Step 5: select the installation path of cygwin. this is the installation path you downloaded. Click the directory where you run setup.exe. Click Next to install cygwin:

6. You have three connection style options:

1) Direct Connection: a direct connection.

2) use ie5 settings: use IE's connection parameter settings to connect.

3) Use http/FTP Proxy: Use http or FTP agent to connect to the server (enter the server address and terminal slogan ).

Users can choose according to their own collection and connection scene. Generally, under normal scenes, the first type is selected, that is, the direct connection style format. Then click "Next ",

7, this is the choice to download the site, I use a http://mirrors.kernel.org, the speed of feeling infection is quite fast, after the selection of the next step

8. The installation package list will be downloaded.

9. Search indicates the name of the package you want to download. You can quickly filter out the package you want to download. The four single-choice buttons select the style of the bottom tree. By default, they do not need to be moved. The default value of view is category. We recommend that you change it to "full" to display all the packages and check them again, saving some of the packages hidden. The check box in the lower left corner shows whether to hide the expired package. By default, you just need to check it. Download the package we want to install at the beginning to avoid full-hand download, the following packages used by ndk are listed: autoconf2.1, automake1.10, binutils, GCC-core, and GCC-
G ++, gcc4-core, gcc4-g ++, GDB, PCRE, PCRE-devel, gawk, make a total of 12 packages

10. Choose to install these packages, click skip, and turn it into a digital version pattern. Make sure that the bin item is converted into a cross sign, and the SRC item is the source code. This is not required.

11. Test whether cygwin has been installed.

Run cygwin. In the pop-up command line window, enter the cygcheck-C cygwin command to print the current cygwin version and running status. If the status is OK, cygwin runs normally.

Input gcc-V, G ++ -- version, make-V, and GDB-V in sequence for testing. If both print the published information and some description information, I am very excited to tell you, your cygwin installation is complete!


3. device ndk scene variable

1. First find cygwin's installation directory and find a home <your user name>. bash_profile file. Mine is: D: cygwin/home/Administrator /. bash_profile, (pay attention to: My home folder was not installed under the Shenma, solution: First open the scene variable, delete the home variable in the user variable, in E: under the cygwin/home folder, create a folder named Administrator (the user name), and then set D: cygwin/etc/skel /. bash_profile ).

2. Open the bash_profile file and add ndk =/cygdrive/<your drive letter>/<Android ndk directory> For example: ndk =/cygdrive/e/android-ndk-r8

Export ndk

The ndk name is random. For future convenience, select a short name and save it.

(If the character is bad, finally. /build_native.sh will prompt Please define ndk_root copy/etc/defaults/etc/skel /. bash_profile file to the/home/user name/directory (it seems to be a bug in cygwin1.7.17-1 ))



4. Configure create-android-project.bat

\ Cocos2d-2.0-x-2.0.3 \ create-android-project.bat


1. Modify Your cygwin path, for example, C: \ cygwin \ bin.

2. Modify the path to your Android-SDK, for example, D: \ Android-SDK \ tools.

3. Modify your Android-ndk path for example: D: \ Android \ eclipse \ android-ndk-r7


5. Run the create-android-project.bat


Enter the program name as prompted and select android to create the hello Android project.

(If the character is bad, you will be prompted that xcopy is not an internal command. This is a command in c: \ windows to check whether it exists. If yes, set the PATH environment variable to add % SystemRoot % \ system32; % SystemRoot % \ system32 \ WBEM; if it does not exist, download it and place it under D: \ Android-SDK \ tools)



6. Add the project to eclipse

After being added to eclipse, errors will be reported for various reasons.

Copy the code under \ cocos2d-2.0-x-2.0.3 \ cocos2dx \ platform \ Android \ Java \ SRC to [your project] \ proj. Android \ SRC

7. Run./build_native.sh.

Open cygwin and go to [your project] \ proj. Android \ directory./build_native.sh to generate the. So file.

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.