How to build a Windows Android C ++ Development Environment (1)

Source: Internet
Author: User

// ================================================ ====================================
// Title:
// How to build a Windows Android C ++ Development Environment (1)
// Author:
// Norains
// Date:
// Thursday 14-rjl-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/is always under no law, so we can use the search engine to search for it. For your convenience, here is a direct download URL: http://dl.google.com/android/ndk/android-ndk-r5b-windows.zip. However, although I downloaded it from here, it does not mean that you can continue to use it when you see this article.

 


2. decompress the ndk

 

Decompress the downloaded ZIP file. The path here is: D:/ProgramFiles/Android/ndk. Although the path is arbitrary, do not include spaces as much as possible.

 


3. Download cygwin

 

Android uses the core of Linux and is destined to write programs for it. It cannot use Microsoft's Visual Studio stream. Moreover, Google also recommends using Linux to develop C ++ programs. The problem is that there are too many people using Windows, even programmers. So does this mean we have to switch to Linux? It is not necessary. We only need to download a cygwin to solve the problem.

 

Where is cygwin? It is actually a collection of Linux tools. It can build a Linux environment in windows, so that you can develop Linux programs in windows. Its official website is http://www.cygwin.com. Only when the software license needs to be downloaded using the setup.exe file on the official website, and the complete cygwin file cannot be found on the network, the result is that without the commonly used download software, you can only wait slowly.

 

Click the setup.exe program to display a dialog box for selecting the download method. Because I used to back up the installation files to facilitate installation on the second machine, I chose the second item: "download without installing ",

 

After a series of "Next" operations, a dialog box is displayed for selecting to download components. To avoid inexplicable problems in the future, I suggest you install them all ,:


If you download the entire cygwin in install mode, the size is about 1.7g, so it is a long process. In particular, we cannot use our usual download tools, and the server is abroad, increasing the length of time consumed.


4. Install cygwin

 

Still click the setup.exe program, but this time we chose: "Install from local directory ",



Next, select the installation directory. Here I am "D:/ProgramFiles/cygwin ",:



Next, select the path of the cygwin package you downloaded. Here, the path is "D:/tools/cygwin ",:



Some may be unable to determine their own installation path. In fact, the local installation package path is the folder where the setup. ini file is located.

The installation component is the same as before. Select install as all components. After clicking Next, wait for the end of the long installation process, as shown in:


5. Set Environment Variables

 

After the installation is complete, it is best to set the corresponding environment variables to facilitate ndk compilation. Open the home folder under cygwin's installation directory and enter the corresponding user name. If you find that this user name has. the bash_profile file is much simpler. use NotePad to open the file and add the following text at the end of the file:
# Create an ndk path. In Windows, my path is D:/ProgramFiles/Android/ndk.
Ndk_root =/cygdrive/D/ProgramFiles/Android/ndk
# Add to Path Environment Variable
Export ndk_root


After saving the file, open cygwin and enter CD $ ndk_root in the command line. Note that, unlike CMD in Windows, it must be case sensitive. If there is no accident, it will go to our ndk installation directory.

If the corresponding user name Folder does not change the file, the problem may not be that simple. If you have created a. bash_profile under the user name, added the corresponding text, and everything is normal as described above, congratulations! But in fact, it is often not so smooth. You may find that even if the file is created under the user name, it seems that the environment variable is not set successfully. This is probably because the path where the user name is located is incorrect. To verify the path, enter PWD in cygwin.

For example, enter PWD after installation, and the screen displays:



This means that if I put. bash_profile in D:/ProgramFiles/cygwin/home/administrator, it will not work, but should be placed in D:/workplace!

So, can we change this directory? The answer is yes. You only need to modify the corresponding environment variables. Right-click my computer and select Properties> advanced> environment variables as follows. In the above or below box, find the home environment variable and change it to the corresponding value. After the change, restart the computer, copy. bash_profile to the path pointed to by the home variable, and start cygwin. Then the change takes effect. Note that you must restart your computer. Otherwise, the value before the home variable may affect cygwin.

After the value of the home variable is changed, enter PWD. It is obvious that the path has changed and the ndk_root variable also takes effect,



6. Compile the program

 

Next, let's compile a program.

 

First, go to the D:/ProgramFiles/Android/ndk/samples/Hello-JNI path on the cygwin command line interface. If you are not familiar with the command line, enter the following command: CD/cygdrive/D/ProgramFiles/Android/ndk/samples/Hello-JNI

Then input "$ ndk_root/ndk-build" to compile. $ Ndk_root is the environment path set in. bash_profile, while ndk-build is the compilation tool that calls ndk. If no problem exists, it will generate a libs directory, and all the. So files generated by compilation will be here, as shown in:



Start the configured Android Java development environment, such as Eclipse + CDT, and create an android project. Select Create project form existring source location = D: /ProgramFiles/Android/ndk/samples/Hello-JNI. After confirmation, compile and generate the APK file, and then run the program. Next article will explain how to build an eclipse + CDT compiling environment to compile Android programs.

 

 


References:
 
Guide for completely downloading cygwin (I)
Http://blog.csdn.net/Lionwoo/archive/2005/08/06/446962.aspx

 

Build Android native C/C ++ Development Environment on Windows
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/

 

Integrating cygwin and eclipse with Android ndk R5 in Windows
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.