4 years ago (2016-01-08)  Software development |   First to comment  8 
post score 0 times, average 0.0

NDK (android native develop kits): android local development kits, you can put c/c++ -> compile into a binary file that can be executed under Linux. The java code can be used to execute binary files through jni. What is JNI: java local development interface, JNI is a protocol This protocol is used to communicate java code and external native code (c/c++). Through this protocol, java code can call external c/c++, code outside c The /c++ code can also call java code. Java can achieve the development of the upper application, but can not write the underlying driver, some android projects must deal with the underlying hardware, such as to accurately and quickly obtain the value of a sensor, then java can not be done, then what to do, through JNI Development, complete the underlying driver or worth it via c/c++, then pass the value back to the java layer.The same java layer can also pass data to the c/c++ layer, so that data interaction is done through the JNI. android_studio_NDK

Why use NDK?

In summary, it is mainly divided into the following situations:
  • 1. Code protection, because the java layer code of apk is easily decompiled, and C/C++ library is relatively difficult to reverse.
  • 2. Call third-party C/C++ libraries in the NDK because most of the open source libraries are written in C/C++ code.
  • 3. Easy to transplant, libraries written in C/C++ can be used again on other embedded platforms.

MainActivity:

The following is automatically generated by the javah command

cn_wangbaiyuan_ndktest_MainActivity.h

  Add the following configuration in build.gradle(Module:App) to specify the type of CPU platform that generated the .so file and the name of the so file. If not specified, android will generate libapp.so and all platform so files; generate so files The path is: your project's root directoryappbuildintermediatesndkdebuglib

Build.gradle(Module:App)

   

 

This article has been printed on copyright and is protected by copyright laws. It must not be reproduced without permission.If you need to reprint, please contact the author or visit the copyright to obtain the authorization. If you feel that this article is useful to you, you can click the "Sponsoring Author" below to call the author!

Reprinted Note Source: Baiyuan's Blog>>https://wangbaiyuan.cn/en/first-android-ndk-program-2.html

Post comment

Style

No Comment

登录

Forget password?

您也可以使用第三方帐号快捷登录

切换登录

注册

TW