Build an ndk development environment using eclipse (eclipse-jee-juno-SR1-win32-x86_64 4.2)

Source: Internet
Author: User

Build an ndk development environment using eclipse (eclipse-jee-juno-SR1-win32-x86_64 4.2)

1. About ndk:

Ndk stands for Native Development Kit.

1. 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 MK files to isolate differences such as CPU, platform, and Abi, 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.

2. 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 ).

Ii. Download and install Android ndk


1.
Preparation.

Build the android Development Environment (not to mention .)

Download plug-in: ndk R8 (to correspond to your own eclipse j2eeide version) Latest: http://developer.android.com/sdk/ndk/index.html


 
2. Download and install cygwin

Since make and GCC must be used to compile the ndk code, you must first build a Linux environment. cygwin is a UNIX simulation environment running on Windows, it is very useful for learning Unix/Linux operating environments or porting applications from UNIX to Windows. With this feature, you can use ndk to compile C and C ++ code without installing Linux. Next we will install cygwin step by step.

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

3. Double-click "run". After running, you will see the Installation Wizard interface.

4. click Next.

In this case, select the installation method:

1) install from Internet: Download the package directly from the Internet and install it immediately (after the installation is complete, the downloaded package will not be deleted, but will still be retained so that the package can be installed again next time ).

2) download without installing: Download the installation file to your local computer, but it is not installed yet.

3) install from local directory: without downloading the installation file, install it directly from a local directory containing the installation file.

5,Select the first item and click Next:


6
,Select the directory to be installed. Note that it is best not to place it in a directory with Chinese characters and spaces, which may cause installation problems. Other options do not need to be changed. Then click Next:


7
,The installation step is to select the cygwininstallation Directory, which is the directory where you run setup.exe. Click Next to install cygwin:


8
At this time, you have three Connection Methods:


1) Direct Connection: a direct connection.

2) use ie5 settings: Use the connection parameter settings of IE to connect.

3) Use http/FTP Proxy: Use http or FTP Proxy Server for connection (you need to enter the server address and port number ).

You can select based on your network connection. Generally, you can select the first method, that is, direct connection. Then click "Next ",

9,This is the choice to download the site, I use a http://mirrors.kernel.org, the speed is still very fast, click Next

10,The installation package list is downloaded.

11,You can enter the name of the package you want to download in search to 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 show all packages and check them again. Save some of the packages to be 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 below to avoid downloading it all, the following packages used for ndk development 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

12,Then, choose to install these packages, click skip, and convert it to the digital version format. Make sure that the bin item is converted to the cross sign, and the SRC item is the source code. This is unnecessary.

13,Next, we will test whether cygwin has been installed.

Run cygwin. In the displayed 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.

Enter GCC -- version, G ++
-- Version, make -- version, GDB
-- Version is used for testing. If you print all the published information and some description information, we are very happy to tell you that your cygwin installation is complete!

14,Configure ndk Environment Variables

1) First, find the installation directory of cygwin and find a home \ <your username> \. bash_profile file. Mine is: e: \ cygwin \ home \ Administrator \. bash_profile, (note: I didn't have any Trojans in my home folder during installation. Solution: First open the environment variable and delete the home variable from the user variable. In E: in the \ cygwin \ home folder, create a folder named "Administrator" (user name), and then set E: \ cygwin \ etc \ skel \. bash_profile ).

2) Open the bash_profile file, add ndk =/cygdrive/<your drive letter>/<Android ndk directory> For example: ndk =/cygdrive/e/android-ndk-r5

Export ndk

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

3) Open cygwin and enter CD $ ndk. If the/cygdrive/e/android-ndk-r5 information configured above is output, it indicates that the environment variable is set successfully.


15. Use ndk to compile the program

1,Now let's use the installed ndk to compile a simple program. Let's choose the built-in ndk example hello-JNI, my location is E: \ android-ndk-r5 \ samples \ hello-JNI (depending on your installation location ).

 

2,Run cygwin and enter the command CD/cygdrive/e/android-ndk-r5/samples/Hello-JNI to go to the E: \ android-ndk-r5 \ samples \ hello-JNI directory.

3,Enter $ ndk/ndk-build. After successful execution, it will automatically generate a libs directory and put the. So file generated by compilation in it. ($ Ndk is used to call the environment variable we configured previously, and ndk-build is used to call the Compilation Program of ndk)

4,Go to the libs directory of hello-JNI to check whether the. So file is generated. If yes, your ndk will run normally!

3. Integrate the C/C ++ development environment in eclipse

1. Install the C/C ++ environment plug-in of Eclipse: CDT. Select online installation.


First, log on to http://www.eclipse.org/cdt/downloads.php and find the on-line installation address of your own cdtplug.

2. Click the Help menu and find the install new software menu.

3. Click the Add button and enter the obtained address. After the plug-in list is displayed, select all. Then, select next to complete the installation.

4. After the installation is complete, right-click a new project in eclispe. If the C/C ++ project appears, your CDT plug-in is successfully installed!

Note: The following error is prompted when you install new software through help-> install new software:

 

Cannot complete the install because one or more required items cocould not be found.
Software being installed: C/C ++ Remote launch 6.0.0.201%151620 (Org. Eclipse. CDT. Launch. Remote. feature. Group 6.0.0.201%151620)
Missing requirement: C/C ++ remote debug launcher 2.3.0.201511151620 (Org. eclipse. CDT. launch. remote 2.3.0.201%151620) requires 'bundle Org. eclipse. RSE. ui [3.0.0, 4.0.0) 'But it cocould not be found
Cannot satisfy dependency:
From: C/C ++ Remote launch 6.0.0.201%151620 (Org. Eclipse. CDT. Launch. Remote. feature. Group 6.0.0.201%151620)
To: org. Eclipse. CDT. Launch. Remote [2.3.0.201511151620]

 

Solution:

The error message above shows that org. Eclipse. RSE. UI is missing.

On eclipse, we can find the differences between different versions of Eclipse: http://www.eclipse.org/downloads/compare.php

 

The comparison shows that eclipse integrated with CDT has An RSE component, so download the RSE component separately:

RSE-runtime-3.3.1.zip http://www.eclipse.org/tm/

An error occurred while installing RSE through help-> install new software. Regardless of this, the files that are directly decompressed are copied to the corresponding eclipse directory. You can. This problem can be solved.

 

1. Open eclipse and import the hello-JNI example that comes with ndk,

2. You must be tired after this process. Congratulations again, the compilation configuration is complete. Now, let's test whether automatic compilation can be performed, open the hello-jni.c file in the project JNI directory and prompt hello from JNI! Change it to another text, such as hello, my name is Alex., and then run your program in the simulator. If the simulator displays your latest modified text, then congratulations! You have all configured successfully!

 

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.