How to build the Android C + + development environment for Windows

Source: Internet
Author: User

Original address: http://www.apkbus.com/android-18595-1-1.html

//=====================================================================
TITLE:
How to build Windows Android C + + development environment (i)
AUTHOR:
Norains
DATE:
Thursday 14-april-2011
Environment:
Cygwin 1.7.9
Android NDK R5
//=====================================================================

1. Download Android NDK

Normally, we can download the NDK from the official website, but it seems that http://developer.android.com/has not been able to open it, so search through a search engine to find a free download. For the convenience of everyone, I am here to give a direct download URL: http://dl.google.com/android/ndk/android-ndk-r5b-windows.zip. However, although I downloaded from here, it does not mean that when you see this article, you can continue to use.


2. Unzip the NDK

Unzip the zip file that you downloaded back. My path here is: D:/programfiles/android/ndk. Although the path is arbitrary, do not include spaces as much as possible.


3. Download Cygwin

Android is the Linux kernel, destined for its program is not possible to use Microsoft's Visual Studio, and Google also recommended the use of Linux to develop C + + programs. The problem is that there are too many people with windows, even for the programmer community. So does that mean we have to turn to Linux? It's not really necessary. We only need to download a Cygwin to solve the problem.

Where is this Cygwin sacred? It's actually a collection of Linux tools. It can build a Linux environment under Windows, allowing you to develop Linux programs under Windows. Its official website is: http://www.cygwin.com/, we can download it by ourselves. Only the software must be used on the official website of the Setup.exe file for download, and the network can not find the full Cygwin, so directly bring us the result is that there is no common download software, only slowly wait for the turtle speed.

Clicking on the Setup.exe program will bring up a selection of Download Options dialog box. Because I am used to backing up the installation files to facilitate the installation of the second machine, I chose the second item: "Download without installing",
<ignore_js_op>
After a series of "Next", a dialog box is selected to download the component. In order to avoid strange problems in the future, I would recommend that you choose Install all the following:
<ignore_js_op>
Install to download the whole Cygwin, the size of about 1.7G, so doomed this is a relatively long process. In particular, we can not use our usual download tools, and the server in foreign countries, but also exacerbated the time-consuming length.


4. Installing Cygwin

Still click Setup.exe this program, but this time we chose: "Install from Local Directory",
<ignore_js_op>
Then choose the installed directory, I am here "D:/programfiles/cygwin",:
<ignore_js_op>
Next, the choice is you download back the path of the Cygwin package, and I here path is "D:/tools/cygwin",:
<ignore_js_op>
Some friends may not be able to determine their own installation path, in fact, it is very simple, the local installation package path is Setup.ini This file is located in the folder.

The next installation component is the same as before, all selected as install. After you click Next, wait for the end of the lengthy installation process, as shown in:
<ignore_js_op>
5. Setting Environment variables

After installation, it is best to set the appropriate environment variables in order to facilitate the compilation of the NDK. Open the home folder under the Cygwin installation directory, and then go to the appropriate user name, if you find that the user name has a. bash_profile file, then the next simple, open the file directly with Notepad, and then add the following text at the end of the file:
#创建NDK的路径, my path in Windows is: D:/PROGRAMFILES/ANDROID/NDK
Ndk_root=/cygdrive/d/programfiles/android/ndk
#添加到PATH环境变量中
Export Ndk_root

After saving, open Cygwin, enter: CD $NDK _root on the command line. Note here, unlike the cmd under Windows, this must be case-sensitive. If it is not an accident, it will go to our NDK's installation directory.

If the corresponding User name folder does not change the file, the problem may not be so simple. If you create a. Bash_profile in the user name and add the appropriate text, then as said above all normal, then congratulations! But in fact, it's often not so smooth. It is likely that you will find that even though we have created the file under the user name, it seems that the environment variable is not successfully set at all. This is likely to be the user name of the path set is not correct, to verify the path, directly in the Cygwin input pwd.

For example, after I install, enter PWD and the screen displays:
<ignore_js_op>
This means that if I put the. Bash_profile into D:/programfiles/cygwin/home/administrator There is no effect and should be put to d:/workplace!

So, do we have a way to change this directory? The answer is yes, as long as you modify the appropriate environment variables. Right-click on my Computer and choose from the following path: Properties, advanced, environment variables. In the box above or below, find the home environment variable and change it to the appropriate value. After the change, restart the computer, copy the. Bash_profile to the path that the home variable points to, start the Cygwin, then it will be effective. Note that it is important to restart the computer, otherwise the value before the home variable may also affect the Cygwin.

After changing the value of the home variable, enter PWD, it is clear that the path has changed and the ndk_root variable has worked,<ignore_js_op>
6. Compiling the program

Next, we will compile a program to try.

First, go to the D:/programfiles/android/ndk/samples/hello-jni path in the Cygwin command line interface. If you are unfamiliar with a command line friend, you can enter the following command: Cd/cygdrive/d/programfiles/android/ndk/samples/hello-jni

Then enter "$NDK _root/ndk-build" to compile. $NDK _root is the environment path set previously in. Bash_profile, and Ndk-build is the compilation tool that calls the NDK. If it does not, it will generate a libs directory, and the generated. So file will all be here, as shown in:
<ignore_js_op>
Launch the configured Android Java development environment, such as Eclipse + CDT, then create an Android project, choose Create Project Form existring Source Location =d:/ Programfiles/android/ndk/samples/hello-jni, you can start compiling and generating the APK file after you confirm, and then run the program. To build an Eclipse + CDT compilation environment to compile the Android program, we will explain the next article.



Reference documents:

"Cygwin full download Guide (top)"
Http://blog.csdn.net/Lionwoo/archive/2005/08/06/446962.aspx

Android native C/D development environment built under Windows platform
Http://www.cnblogs.com/FinalKiller/archive/2009/07/11/1520900.html

"Android beginners:ndk Setup Step by step"
http://mindtherobot.com/blog/452/android-beginners-ndk-setup-step-by-step/

Windows system integration Cygwin with Eclipse and using Android NDK R5
http://student.csdn.net/space.php?uid=121497&do=blog&id=57864

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.