Anroid ndk: Android ndk Overview

Source: Internet
Author: User

Android ndk Overview

Introduction:

Android ndk is a set of tools that allow program developers to embed computer code compiled by C and C ++ into their application packages.

Important information:


Android ndk can only be used on Android 1.5 or later platforms.

The 1.0 and 1.1 systems are not supported because some minor changes have taken place in the abi and toolchain releases of 1.5.


I.
Android ndk goals:

--------------------------

Android VM allows your application to call methods implemented in local code through JNI. In short, this means:



-Your program code uses the native keyword to declare the method to indicate that they are implemented in the local code. For example:


Native byte []
LoadFile (string
Filepath );


The hosts file. This library must use standard UNIX naming conventions, such as lib <something>. So, and should contain a standard JNI entry (there will be multiple entries later). For example:


Libfileloader. So

-Your program must load the library explicitly. For example, to load it at startup, simply add the following code:


Static {


System. loadlibrary ("fileloader ");


}

Note that you should not use the 'lib' prefix or the '. so' suffix.

Android ndk is a supplement to the android SDK and can help you:



-JNI-compatible shared libraries are generated and can run on Android 1.5 and later platforms that use arm cpu.



-Copy shared library files to your application. When this happens, they will be automatically copied to your final .apk s package.


-In a later version of ndk, we plan to provide tools to help you debug native code through GDB connections and provide as much symbolic information as possible.

In addition, Android ndk provides the following features:


-A set of cross-tool chains (compiler, linker, and so on) that can generate native arm machine code in Linux, OS X, windows, and other systems.


-A set of system header files for the stable native API provided by the Android platform. These header file definitions will be supported in future releases.

Important information:

Remember: Most of the Android system's native system libraries are not static. In the future, the release or upgrade versions of the platform may change dramatically or even be deleted,

-A compilation system allows developers to write a short description of the source code to be compiled. The compilation system handles all the troublesome details about toolchain, platform, CPU, and Abi. In addition, you may add many

Tool chain, platform and system interface support. These support does not require developers to change the file generation (or what other files will be generated later)


Ii. Goals that android ndk cannot achieve:

--------------------------

Ndk is not a good way to write native code running on Android devices. It is particularly emphasized that your applications should still be written in Java to handle Android system events in a timely manner, avoid the dialog box indicating that the program does not respond, or process the lifecycle of the android program.

Note that in any case, it is possible to write a complex program with native code and use a small "Program Package" to properly start/stop it.

Because operations in many environments require specific instructions from developers and cannot be universal when writing native code, we strongly recommend a good use of JNI, which includes:

-You cannot directly access content in VM objects through direct native pointers. For example, you cannot safely obtain a pointer to a 16-character array of string objects, then iterate in the loop.

-When you want to retain the VM object handle in the native code, explicit reference management is required,


Ndk only provides a limited number of header files and libraries supported by the Android platform. However, the android system contains many native shared libraries that are not supported, it should be considered that the Implementation Details may change dramatically in the release and upgrade versions of the platform in the future.

If an Android system is not explicitly supported by the ndk header file, the program should not rely on it; otherwise, the risk of damage will occur in the future upgrade. The selected system library will be gradually added to the stable ndk API.

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.