Android NDK Development (I)-Environment Building

Source: Internet
Author: User

Android NDK Development (I)-Environment Building

 

Android NDK development is an indispensable part of Android development, we can use the JNI bridge to establish connections (mutual calls) between Java and C/C ++ ). So why do we need to know about NDK development in Android development? It is true that there are many sayings about these reasons, which I have summarized. C/C ++ is a programming language older than Java. Due to its ancient features, many excellent class libraries emerged in the early days, such as FFMPEG class libraries for video coding and decoding, these complex class libraries have long been written by C/C ++. When processing video codec, we do not need to repeat the "Wheel", so we can use them directly, however, this direct method is difficult to achieve, because the Java compilation environment is different from the C/C ++ principle, therefore, you must find a link between Java and C/C ++ code, which is JNI. Another important reason is the efficiency. Java is a cross-platform language and has different JVM implementations on different platforms. The Java source code must be compiled first. class file, and then. class files run on different JVM interpretation executions. Such steps result in a waste of efficiency. The difference is that C/C ++, which can be directly compiled into binary files on a specific platform, it runs directly on a specific platform, which is much more efficient than Java. Therefore, in some specific environments, you still need to use C/C ++ to solve the efficiency problem, java is only responsible for processing the results returned by C/C ++, so that the interaction between Java and C/C ++ is very important.

Before developing NDK, you 'd better understand the C/C ++ syntax. Generally, this part of the Code does not need to be written by Android programmers, but Android programmers are better at understanding the C/C ++ source code, this will get twice the result with half the effort. Learning about C/C ++ syntax is not the focus here. If you are interested, you can directly learn from materials, please extract the Emy teaching material "C language programming-tan haoqiang" from the bottom of the Cabinet, pat the dust above, just once ^. ^

I. clarify some basic concepts 1. JNI

Java Native Interface interfaces developed locally by Java. JNI is a protocol used to communicate java code with external local code (c/c ++ ). Through this protocol, java code can call external c/c ++ code, and external c/c ++ code can also call java code.

2, CDT

C/C ++ Develop tools and C/C ++ development tools. Is a plug-in on Eclipse, mainly to enable C/C ++ code to be highlighted. This component is not necessary unless you are a C/C ++ expert and like to write code on notepad. For general programmers, please install it. Highlighting is very important.

3, NDK

Native Develop Kits, a local development kit. This kit is very important. It is a tool set provided by Google to develop JNI programs on Android. With it, it will make development more efficient.

4. cygwin

Linux simulators in Windows. We all know that Android is a Linux kernel-based operating system. Therefore, when compiling C/C ++ source code, you must use the Linux environment to compile it into a file on a specific Linux platform. so or. a. The good news is that the NDK high version provides support for Development kits in Windows, and cygwin can be used instead. It is also feasible to Compile directly on the Windows platform, but in order to display and learn, it is better to know something about it.

 

2. Set up the NDK environment. 1. Install CDT. skip this step if the complete set of IDE integrated with ADT is downloaded from the Android Develop official website, because the CDT plug-in has been integrated in ADT, you can use it directly. If you are using a traditional Eclipse plug-in, you can install CDT in two ways. (1) download the CDT plug-in for installation. On the Eclipse Community official website, you can find the download link https://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 for expansion, select Programing language




Select c/c ++ development tools


Next, agree to licenses.

If the installation is successful, you will be prompted if you want to restart eclipse. The installation will be completed after the restart.


2. Install cygwin

NDK needs to run in linux, and cygwin is a tool used to simulate linux in windows. Cygwin is a program that supports many plug-ins. You can download idea from the official website of cygwin:Http://download.csdn.net/detail/lee_tianya/8235323


Please note when selecting the installation method. Generally, you can choose to install it online from the Internet, but it is slow and cannot be disconnected. If the network speed is poor, you must download it from the beginning, very uncomfortable. The second method is local installation. First download the files required for installation and place them on the local disk. Then select the installation directory. Here, I will install them locally.

When selecting the installation directory, note that the installation directory cannot contain spaces. It is best not to contain non-English characters such as Chinese characters.




After the installation is complete, a shortcut icon appears on the desktop. Double-click the shortcut icon to open cygwin.

First, the program will initialize

 

Run the command

Make-v

 

The GNU Make version is displayed, indicating that the linux compiling environment simulated by cygwin has been successfully simulated.

 

3. Install NDK

First, go to the official website of Google Android Develop to download the NDK. The address isHttp://developer.android.com/tools/sdk/ndk/index.html

 

Upload. After the download is complete, click the exe file and the package will be automatically decompressed to the current directory. This process is quite long. It can be seen that the installation is too large due to the upgrade. Well, after decompression, I will move E: /NDK directory.

After completing the above steps, the environment is basically built, now we use cygwin to simulate the Linux environment, enter the Windows path E:/NDK/android-ndk-r10d, run the ndk-build script.

Step 1: Go to the root directory and find the cygdrive file under the root directory. This file corresponds to all the drive letters in Windows:

 

Step 2: Go to the ndk directory:

 

Step 3: Execute the ndk-build script

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

 

To use ndk-build directly in the command line, you need to add the ndk directory to cygwin's environment variable.

First

Find the etc/profile file in the cygwin installation directory, which is the configuration file of cygwin. Open this file in notepad and find the following line:

Then

We found the ndk decompression path on the cygwin console.

Next

Copy this Path to the Path. Note that the Path division in Linux environment variables is distinguished by the colon ":".

Finally, check whether the configuration is complete. Enter the "ndk-build" command in the cygwin console. If the command line displays the information shown in, the configuration is complete and can be used, if this is not the case, configure it again according to the description in the article.
Now that the environment for NDK development is complete, you can use the NDK environment for development. For more information about NDK development, see the following articles.

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.