[Android -- JNI and NDK] Know NDK

insert image description here

Introduction

Definition : Native Development Kit is a tool development kit for Android.

NDK belongs to Android and has no direct relationship with Java

Function : Rapidly develop C and C++ dynamic libraries, and automatically package so and applications into APK

You can use JNI to interact with native code (such as C, C++) in Android through NDK

Application scenario : use JNI in the Android scenario.

Features :
insert image description here

Steps for usage

  • 1. Configure the Android NDK environment

  • 2. Create an Android project and associate it with NDK

  • 3. Declare the Native method that needs to be called in the Android project

  • 4. Use the native code that Android needs to interact to implement the Native method declared in Android.
    For example, if Android needs to interact with C++, then use C++ to implement the Java Native method

  • 5. Compile and generate the .so library file through the ndk - bulid command

  • 6. Compile the Android Studio project to realize Android calling local code

NDK and JNI relationship

insert image description here

Android Studio 2.2 or above implements NDK

Because Android Studio 2.2 and above have integrated NDK, you only need to configure it inside Android Studio

Step 1: Follow the prompts to create a project

When creating a project, you need to configure NDK and install it step by step according to the prompts.
insert image description here

Step 2: Use NDK according to your needs

  • After configuring the NDK, Android Studio will automatically generate the C++ file and set the calling code
  • You only need to modify the C++ file according to your needs & Android can use it.

insert image description here

Guess you like

Origin blog.csdn.net/duoduo_11011/article/details/131301364