Generate native class header files based on native class 

1> As shown in the figure below, com.lhs.serial.ObdNative is a self-built native class; 2> CMD go to the project Java directory and enter javah -d.. / jni com. LHS. Serial. ObdNative; 3> com_lhs_serial_ObdNative. H; 4> create. CPP, implement com_lhs_serial_ObdNative. H;Copy the code

2. Compile. CPP and generate

1> Create android. mk in the jni directory   

2> Modify Gradle to automatically compile.cpp according to Android.mk

Build. gradle configuration in app directory

Android {compileSdkVersion 25 buildToolsVersion "25.0.2 defaultConfig {applicationId" com. MCT. Interation. Service" MinSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" externalNativeBuild {ndkBuild{abiFilters 'armeabi-v7a' } } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } externalNativeBuild { ndkBuild{ path 'src/main/jni/Android.mk' } } } task ndkClean(type: Delete) { delete ".externalNativeBuild/" } clean.dependsOn 'ndkClean'Copy the code

Build. Gradle in the root directory of the project. Gradle in the class path must be 2.2.0 or higher.

  

3. After completing the above steps, when running the project,.so will be generated automatically and packaged into APK

[Problems encountered]

1.Could not find method externalNativeBuild() for arguments”Action”


I have been engaged in Android Camera related development for 5 years

Now I work in Shenzhen

Welcome to follow my wechat official account “Xiaochi Notes”.

We learn and communicate together