Android NDK Development Primer _android

Source: Internet
Author: User

Mysterious Android NDK developers are often excited by many programmers, but do not know what it is, due to the recent development of applications, In order to be developed. apk file is not interpreted by others (decompile), consulted a lot of information, including the use of NDK development, with a curious psychology, through online video education website, I understand the mystery of the NDK, the good things naturally to share, next we will come to meet the Android NDK development.

I. Background of the creation of NDK

Since its inception, the Android platform has supported C and C + + development. As we all know, the Android SDK is based on Java implementation, which means that third-party applications that are developed based on the Android SDK must use the Java language. But this is not equivalent to "Third-party applications can only use Java." When the Android SDK was first released, Google claimed that its virtual machine Dalvik supported JNI programming, where third-party apps could invoke their own C-dynamic libraries through JNI, meaning that the "java+c" programming approach was always achievable on the Android platform.

However, Google also said that the use of Native SDK programming compared to the Dalvik virtual machine also has some disadvantages, the Android SDK documentation, can not find any help in JNI. Even if third party application developers use JNI to complete their own C Dynamic link library (so) development, how so how to package with the application to apk and publish? There are also technical hurdles. For instance, the program is more complex, the compatibility is difficult to guarantee, cannot access the framework api,debug more difficult and so on. Developers need to use them at their own discretion.

So Ndk was born. NDK full name is native Development Kit.

NDK release, so that "java+c" the development of the way to finally become a positive, the official support of the development of the way. NDK will be the beginning of the Android platform to support c development.

Second, why use NDK

1. Protection of code. Because the Java layer Code of APK is very easy to decompile, but the C + + library Reverse sink is very difficult.

2. The existing open Source library can be easily used. Most of the existing open source libraries are written in C + + code.

3. Improve the efficiency of the implementation of the procedure. High-performance application logic will be required to use C development, thereby increasing the execution efficiency of the application.

4. Easy to transplant. The library can be used in other embedded platforms easily.

Iii. NDK Introduction

1.NDK is a collection of a series of tools

NDK provides a range of tools to help developers quickly develop a C (or C + +) dynamic library and automatically package so and Java applications as APK. The tools that help developers are huge.

NDK integrates the crossover compiler and provides the corresponding MK file isolation CPU, platform, ABI, and so on, the developer simply modifies the Mk file (indicating "which files need to compile", "Compile attribute Requirements", etc.) to create the so.

NDK can automatically package the so and Java applications, greatly reducing the developer's packaging work.

2.NDK provides a stable, limited-functionality API header file declaration

Google explicitly declares that the API is stable and supports the current published API in all subsequent releases. As you can see from this version of NDK, these APIs support a very limited number of functions, including the C standard library (LIBC), the standard math Library (LIBM), the compression library (LIBZ), and the log library (Liblog).

Iv. Building of NDK development environment

1. Download and install Android NDK

Address: http://developer.android.com/sdk/ndk/index.html

2. Installation DNK

There are many ways to build DNK development of Linux environment, but today we have to explain a little, Google after years of efforts, now NDK installation has been very simple, and support a number of platforms, Today we will be the win platform to introduce how to configure the development environment and Design and development DNK program. First is the installation, the download address provided above is the official website address, we can choose to download according to their own needs, but due to domestic restrictions to visit foreign websites, so download words must FQ,FQ for some programmers is a difficult, here I provide you with a download address: Android-ndk-r9

After the download, the installation DNK is very simple, we will download the. zip file, and then copy the file to any one of our disks.

3. Configure NDK Environment Variables

Learn Java children's shoes, for configuration environment variables must be not unfamiliar, here I will briefly describe how to configure the DNK development environment, right-click My Computer--> Properties--> advanced system Settings--> advanced--> environment variables

In the open environment variable, the system variable finds path, double click, and at the end, add our DNK installation directory.

Here our win environment configuration Android NDK development environment has been completed, we finally through the command line to verify our configuration: Click Start--> input cmd enter--> input ndk-build carriage return, if print out information to indicate our configuration complete.

V. Running NDK provided by the case demo

Run case demo before we need to ensure that our Android development environment has been configured, for the Android development environment configuration, I will not repeat, if you have questions can be a separate message discussion. Let's start by importing the case demo, open the Eclipse Android development environment, then right-click on the blank area and select Import-->android Import:

After we import the project, let's look at the directory structure:

The files under the JNI directory are our. c files, and the. so file in the obj directory is our ndk compiled file, which is our library file. Of course, just imported when the project is not. So file, we need to compile the build, generate the method: start--> input cmd carriage return-->CD Our engineering directory return, see the following diagram operation decomposition:

Here Our example demo is complete, we can allow the test below.

First NDK program: helloword!

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!

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.