Android NDK Development (i)--Environment building

Source: Internet
Author: User

Reprint Please specify source:http://blog.csdn.net/allen315410/article/details/41800955

The NDK development under Android is an integral part of Android development, and with the NDK suite provided by Google, we can use the JNI Bridge to connect (invoke each other) between Java and C + +. So why do you need to know about NDK development in Android development? Admittedly, there are many arguments for these reasons, as I conclude. C + + is older than Java programming language, because of its ancient characteristics, leading to a lot of good early class libraries appear, such as the FFmpeg class library processing video codec, these complex libraries have been written in C + +, we do not need to repeat the "build Wheel" when processing video codec, So can directly take to use directly to use, but this direct method is difficult to do, because the Java compiler environment of the principle and C + + is different, so you have to find a middle person for the Java and C + + code to establish a relationship, the intermediary is the JNI. Another important reason is the efficiency problem, Java is a cross-platform language, on different platforms have different JVM implementations, Java source code needs to be compiled into a. class file first, and then let the. class file run on a different JVM interpretation execution, such steps create a waste of efficiency, but the difference is that C + +, can be directly compiled into a specific platform of binary files, directly run on a specific platform, Efficiency is much more efficient than Java, so in some specific circumstances, you still need to use C + + to solve the efficiency problem, Java is only responsible for processing the C + + return of the results can be, so Java and C + + intermodulation is very important.

Before doing the NDK development, it is best to understand the C + + syntax, usually this part of the code does not need to be written by the Android programmer, but the Android programmer is best able to read C + + source code, this will do more with less, the study of C + + grammar is not the focus here, People interested in the words can directly find information to study, please draw from the bottom of the university teaching materials "C language Programming-rectification", pat the dust above, casually once again ^.^

First, clear some basic concepts 1,jni

Java Native Interface Java-locally developed interface. JNI is a protocol used to communicate Java code and external native code (c + +). With this protocol, the Java code can invoke the external C/C + + code, which can also be called from the external C + + code.


2,cdt

D/C + + Develop tools,c/c++ development tool. is a plug-in on Eclipse, which is primarily to allow C/s + + code to be highlighted. This component is not necessary, unless you are a C + + master, like to write code in Notepad, for the general programmer or install it, highlighting is very important.

3,ndk

Native Develop Kits, Local development kit. This kit is very important and is a tool set that Google provides to us for developing JNI programs on Android, which makes development much more efficient.

4,cygwin

Linux emulator under Windows. You know that Android is based on the Linux kernel operating system, so in the compilation of C + + source code used to use the Linux environment, compile it into Linux-specific platform files. So or. A. The good news is that the NDK version provides support for the development Kit under Windows, Cygwin can not be used, directly under Windows to compile the platform is also feasible, but in order to show learning, it is best to understand a little.


II. NDK Environment Building 1, installing CDT If you are using an integrated ADT IDE that is downloaded from the Android Develop official website, skip this step because the CDT plugin is already integrated in ADT and can be used directly. There are two ways to install the CDT if you are using the traditional Eclipse self-installing plugin. (1) Download the CDT plugin for installation. Download links can be found on the Eclipse community websitehttps://eclipse.org/cdt/。 (2) Online installation. The steps are as follows: Open the Eclipse toolbar Help-->install new software

Select helios-http://download.eclipse.org/release/helios, wait to expand, select programing language




Choose C/D + + Development tools


go down all the way next and agree to licenses.

A successful installation will prompt you to confirm that you restarted eclipse and complete the installation by rebooting.


2, install Cygwin

NDK needs to run in Linux environment,Cygwin is under Windows emulation Linux one of the tools. Cygwin is a program that supports many plugins. You can go to Cygwin's official website to download http://www.cygwin.com/ Double-click Install, or you can download my uploaded package from the CSDN Resources page, which contains the Cygwin installer and installation package, the address is: http://download.csdn.net/detail/lee_tianya/8235323



Choose the installation method please note that you can generally choose to install from the Internet, but the speed is very slow, and can not be broken halfway, if the speed is not good halfway down, then you have to start from the beginning to download, very uncomfortable. The second way is to install locally, first download the necessary files to install the installation on the local disk, and then select the installation directory, I am here to install the Local.

When selecting the installation directory, please note: The installation directory can not appear space, it is best not to appear in Chinese and other non-English characters.




After installation , the Desktop will appear a shortcut icon, double-click the shortcut Small icon, open cygwin.

First the program will initialize


Typing commands

Make–v


Shows the version of GNU make , which demonstrates the success of our Cygwin simulation of the Linux build environment. .


3, install NDK

First go to the wall Google Android develop website to download the NDK, the address is http://developer.android.com/tools/sdk/ndk/index.html



I choose here the Windows version of the 64-bit version of the NDK r10d, is the latest version, Android-ndk-r10d-windows-x86_64.exe, downloaded after the completion of the EXE file, will be automatically extracted to the current directory, the process is relatively long, Visible upgrade caused the installation is too large ah, good, after the decompression I moved the E:/NDK directory.

After doing some of the above steps, the environment is basically complete, and now we use the Cygwin simulation Linux environment to go to the Windows path e:/ndk/android-ndk-r10d and execute the ndk-build script.

First step: Go to the root directory to find the cygdrive file under the root directory, which corresponds to all the drive characters under Windows:



Step Two: Enter the directory where the NDK is located:



Step three: Execute the ndk-build script


Through the above steps, we can use the Ndk-build script, but this process is too cumbersome, the use is very inconvenient, then let's use a simple method, the configuration file.

To facilitate the use of ndk-build directly inside the command line, you need to add the ndk directory to the Cygwin environment variable .

First of all

We found the Etc/profile file in the Cygwin installation directory, this file is the Cygwin configuration file, open this file with Notepad, find the following line:


And then

We found the NDK's decompression path on Cygwin's console.


Next

We copy this path into path and note that the path segmentation in the Linux environment variable uses the English colon ":" to differentiate

Finally check whether the configuration is complete, enter the "ndk-build" command under the Cygwin console if the command line displays the information shown, the configuration is complete and can be used, if not the case, then configure it again according to the description of the article.
Well, the development of the NDK environment in the end of the building, the following can be used in the NDK environment to develop, about the NDK development, the subsequent articles will be introduced slowly.

Android NDK Development (i)--Environment building

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.