Windows Eclipse builds the ANDROID_NDK development environment

Source: Internet
Author: User

Install Cygwin:

Since the NDK compiles code with make and GCC, you must first build a Linux environment, Cygwin is a UNIX simulation environment running on the Windows platform, for learning unix/linux operating environment, or porting applications from UNIX to Windows is useful. With it, you can use the NDK to compile C, C + + code without installing Linux. Let's install Cygwin step-by-step.

The first thing to do is to download the Cygwin installer Setup.exe:

Http://www.cygwin.com

When the download is complete, double-click Run Setup.exe to see the wizard interface as follows:

Click Next and let you choose how to install it:

1) Install from the Internet: downloaded directly from the Internet and installed immediately (after the installation is complete, the download of the installation files is not deleted, but is still retained for the next installation).

2) Download without installing: Just download the installation file locally, but not install it temporarily.

3) Install from the local directory: Do not download the installation files, directly from a locally containing the installation files to be installed.

Select the first item, click Next: Select the directory to install, note, it is best not to put in Chinese and white space in the directory, it seems to cause installation problems, other options do not change, then click Next: The previous step is to choose to install the Cygwin directory, this is to choose the directory where you download the installation package, The default is that you run the Setup.exe directory (that is, the executable file you downloaded setup.exe the directory), I placed in the F:\download directory, and then click Next, at this time you have a total of three connection options: 1) Direct Connection: Directly connected. 2) Use IE5 Settings: Connect using IE's connection parameter settings. 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", this is to select the site to download, I use http://ftp.ntu.edu.tw, (you can also add a site, in the user URL to enter the site of your choice, and then click Add, add in the list selected site) and then click Next: A list of component packages to download will appear: Click Next to proceed to the installation process: Click Finish to complete the installation.

Let's test if the Cygwin is already installed:

Run Cygwin, in the popup command line window input: Cygcheck-c Cygwin command, will print out the current Cygwin version and running state, if the status is OK, then Cygwin run normally. Then enter gcc–version,g++--version,make–version,gdb–version to test, if you print out the version information and some descriptive information, very happy to tell you that your Cygwin installation is complete!

Download Android NDK:

Download site:

Http://dl.google.com/android/ndk/android-ndk-r4-windows.zip

Http://androidappdocs.appspot.com/sdk/ndk/index.html

Http://developer.android.com/sdk/ndk/overview.html

If the above site can not download, but also to the Internet to find some download site, download r4 version of the ANDROID_NDK, download directly after decompression. Consider placing the Android SDK in the same directory, which may bring some convenience to future development.

Configuring NDK Environment variables

First find the Cygwin installation directory, find a home/< your user name >/.bash_profile file, my is C:/cygwin/home/administrator/.bash_profile, (if not found, Then go online and find a solution. Turn on the Bash_profile file and add the following (according to your NDK's installation directory, my is D-disk ANDROID-NDK-R4):

Android_ndk_root=/cygdrive/d/android-ndk-r4

Export Android_ndk_root

Android_ndk_root The name is random, in order to facilitate the use of later, choose a short name, and then save. Open Cygwin, enter CD $ANDROID _ndk_root, and if you output the/CYGDRIVE/D/ANDROID-NDK-R4 information configured above, the environment variable setting is successful.

To install the Eclipse component:

The Android SDK and ADT are not introduced, and a new component,--CDT, is described below. The CDT is a component package for the Eclipse development of C + +, where it is stated that using the NDK to develop Android does not require CDT. If you install the CDT, it will bring some convenience in review someone else's C + + code later. The CSDN can be downloaded to download the CDT compression package, the corresponding directory under pressure to copy the files to the corresponding directory in eclipse.

Deploy and run the first Hello-jni example

To compile the program with the NDK:

Now we use the installed NDK to compile a simple program, we choose the NDK's own example Hello-jni, I am located in D:/android-ndk-r4/samples/hello-jni (depending on your specific installation location), run Cygwin, Enter the command Cd/cygdrive/d/android-ndk-r4/samples/hello-jni and go to the D:/android-ndk-r4/samples/hello-jni directory. Enter $android_ndk_root/ndk-build, after successful execution, it will automatically generate a libs directory, put the compiled. so file inside. ($ANDROID _ndk_root is to call our previously configured environment variables, Ndk-build is called the NDK compiler), at this time go to Hello-jni Libs directory to see if there are any generated. so files, if any, your NDK will run normally!

Configuring parameter compilation in Eclipse generate. So files

1) Import Hello-jni Project

2) At this point your project may be error, it's okay, project right-click Build path->config build path, such as:

Then select Builders->new, such as:

Select program, CONFIGURED as:

An add-on interface appears, starting with a name for the build configuration, such as: C_builder or the default New_builder, for example,

Set location for < you cygwin installation path >/bin/bash.exe program, for example: C:/cygwin/bin/bash.exe;

Set working directory to < your cygwin installation path >/bin directory, for example: C:/cygwin/bin

Set arguments to:

--login-c "Cd/cygdrive/d/android-ndk-r4/samples/hello-jni && $ANDROID _ndk_root/ndk-build"

In the above configuration/cygdrive/e/android-ndk-r5/samples/hello-jni is the directory of the program you are currently compiling, $ANDROID _ndk_root is the environment variable of the NDK that was previously configured, These two are based on your specific installation directory configuration, the other does not change, arguments this string of parameters is actually to the Bash.exe command line program parameters, enter the program directory to be compiled, and then run the Ndk-build compiler program.

Then configure the Refresh option:

Check the refresh resources upon completion

Then configure the build Options option, such as:

Tick the last three items, then click the Specify Resources button, select the Resource directory, tick your project directory:

Finally click Finish, click OK all the way to save the previous configuration, note: If you configure the compiler under other compilers, remember to point up the up button, the first place, or C code compiled later than the Java Code compilation, Will cause your C code to compile two times to see the latest changes, such as, be sure to ensure that new_builder in the first place:

Now to test if you can automatically compile it, open the project JNI directory in the Hello-jni.c file to change the hint Hello from jni! to other text: such as: "Hello,my name is Lusifer." And then run your program in the emulator, If the emulator shows you the latest modified text, then you have all been configured successfully!

Transferred from: http://ygc87.blog.163.com/blog/static/2396065201221063030169/

Windows Eclipse builds the ANDROID_NDK development environment

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.