What is the NDK?
The NDK provides a range of tools to help developers quickly develop C (or C + +) dynamic libraries, and to automate the so and
The Java app is packaged together as an apk. These tools are great for developers.
The NDK integrates the cross compiler and provides the corresponding MK file isolation CPU, platform, ABI and other differences, developers simply need to modify the Mk file (stating "which files need to compile", "compilation characteristics Requirements", etc.), you can create a so. The NDK can automatically package so with Java applications, greatly reducing the developer's packaging effort. To put it simply, the NDK is a cross-compilation tool that can help you compile your code in C or C + + into. So (similar to the. dll) format, which allows you to invoke the code in the Java language (JNI) in your Android program.
the tools you need:
First, Download Installation 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.
First, you have to go to http://cygwin.com/install.html to download setup.exe
Click here to download
1. Then double-click Run, and after running you will see the Installation Wizard interface:
2. Click Next
At this point you choose how to install:
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.
3. Select the first item and click Next:
4, 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:
5, the previous step is to choose to install Cygwin directory, this is to choose the directory where you download the installation package, the default is that you run the Setup.exe directory, directly click the next step:
6, at this time you have a total of three connection options:
1) Direct Connection: Connect directly.
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 their own network connection situation, under normal circumstances, the choice of the first, that is, the direct connection method. Then click "Next",
7, this is the choice to download the site, I use http://mirrors.163.org, speed is very fast, select the next point
8. Download the list of load installation packages at this time
9, search is able to enter the name of the package you want to download, you can quickly filter out the package you want to download. The four radio buttons are the style of selecting the tree below, and by default it's OK to move. View default is category, suggest change to full show all package again check, some of the province's packages are hidden away. The bottom left corner of the check box is whether to hide the expired package, the default tick, do not care it on the line, the bottom to download the package we want to install, in order to avoid all download, here are listed below the development of the NDK needed package: autoconf2.1, automake1.10, Binu TILs, Gcc-core, gcc-, g++, Gcc4-core, gcc4-g++, GDB, Pcre, Pcre-devel, gawk, make a total of 12 packages
10, then start to choose to install these packages, point skip, turn it into a digital version format, to ensure that the bin item into a fork, and the SRC item is the source code, this is not necessary to choose.
List gcc-, g++ installed packages
Attention:
The New column by default is skip, click on him, let him become the version number, and confirm that the Bin column of the small box is a fork. It's OK. If the small box is not forked, click on him to OK
11, download, after the installation is complete, test the Cygwin is not 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 (Note: Version front is two-) to test, if you print out the release information and some descriptive information, very happy to tell you, Your Cygwin installation is complete!
Second, Configuration NDK Environment Variables
1, first find Cygwin installation directory, find a home\< your user name >\.bash_profile file, my is: E:\cygwin\home\Administrator\.bash_profile, ( Note: When I installed my home folder under the god horse do not have, the solution: first open the environment variable, the inside of the user variable to delete the home variable, in the E:\cygwin\home folder to create a folder named Administrator (is the user name), Then copy the E:\cygwin\etc\skel\.bash_profile to the folder).
2. Open the Bash_profile file, add ndk=/cygdrive/< your drive letter >/<android NDK directory > For example:
ndk=/cygdrive/e/android-ndk-r8d
Export NDK
The NDK name is random, for the convenience of later use, choose a short name, and then save
3, open Cygwin, enter the CD $NDK, if the output of the/CYGDRIVE/E/ANDROID-NDK-R8D information configured above, it indicates that the environment variable setting is successful.
Third, with NDK to compile the program
1, now we use the installed NDK to compile a simple program, we choose the NDK's own example Hello-jni, I am located in E:\android-ndk-r8d\samples\hello-jni (depending on your specific installation location),
2, run Cygwin, enter the command Cd/cygdrive/e/android-ndk-r8d/samples/hello-jni, enter into the E:\android-ndk-r8d\samples\hello-jni directory.
3, input $ndk/ndk-build, after successful execution, it will automatically generate a libs directory, the compiled generated. so file inside. ($NDK is to invoke the environment variables we configured earlier, Ndk-build is the compiler that calls the NDK)
4, at this time to hello-jni the Libs directory to see if there are no generated. So files, if any, your NDK is functioning properly!
Windows system installed with the use of Android NDK r8d (one)