Introduction to JNI
JNI (Java Native Interface), Java Local interface
JNI is one of the many Java development technologies that are designed to leverage native code to provide more efficient and flexible development of Java programs. The application scenarios include: the implementation of the efficiency-sensitive algorithm, cross-platform application porting, invoking the system's underlying driver, calling the hardware, etc. Although Java has always been known for its good cross-platform, the True cross-platform king should be C + +, as 90% of the world's systems are written in C/S. Java's cross-platform, is to sacrifice efficiency in exchange for a variety of platform compatibility, so JNI can be said to be the Java Short Board supplement! As an example, the current popular mobile operating system Android, has been said that the system operation is not as fluent as iOS, because the Android app is based on Java development, iOS is based on the object-c development, the difference is the same operation, on iOS on the completion of an instruction , you need more than one command on Android to complete! So in the Android Jellybean version, Google introduced the Projectbutter (butter program), used a lot of local libraries in the application layer, and optimized the architecture of the system to improve the overall operation of the Android system response!
In short, JNI is a technology that is a bridge between Java code and C + + code!
Let's review the Android system architecture diagram:
Why use JNI
1, extended JVM function, Access driver, operating hardware (Internet of things, smart home, car computer)
2, the efficiency of C + + language more efficient math operations, real-time rendering of the game, audio and video processing
3, Java Anti-compilation is easier than C language, through JNI Enhanced code security (encryption algorithm put to C implementation)
4, code porting, re-use the existing C code (Opencv,ffmpeg ... )
How to use JNI?
1.c/c++ language
2. Mastering the Java JNI process
3.NDK (native develop kits)
About NDK
1.NDK is a collection of a range of tools
The NDK provides a range of tools to help developers quickly develop C (or C + +) dynamic libraries and automatically package so and Java applications together as 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.
2.NDK provides a stable, feature-limited API header file declaration
Google expressly declares that the API is stable and supports the currently published API in all subsequent releases. As seen from this version of the NDK, these APIs support a very limited number of features, including: C standard library (LIBC), Standard math Library (LIBM), compression library (LIBZ), log Library (Liblog).
Introduction to Android JNI