步骤:
1. build.gradle 配置如下,主要两项 ndk 和 sourceSets
apply plugin: ‘com.android.application‘ android { compileSdkVersion 28 buildToolsVersion "29.0.1" defaultConfig { applicationId "com.shuguo.myapplication" minSdkVersion 21 targetSdkVersion 28 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" ndk { moduleName "native-lib" ldLibs "log", "z", "m" abiFilters "armeabi", "armeabi-v7a", "x86" } } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt‘), ‘proguard-rules.pro‘ } } sourceSets { main { jniLibs.srcDirs = [‘src/main/jni/libs‘] } }}2. 创建jni目录,file->new->folder->jnifolder3. 配置ndk-build 4. 创建.h文件,cpp文件5. 编写Android.mk
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS) LOCAL_MODULE := native-libLOCAL_C_INCLUDES := com_shuguo_myapplication_JniClass.hLOCAL_SRC_FILES := com_shuguo_myapplication_JniClass.cpp LOCAL_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY)6. 编写Application.mk
APP_ABI := armeabi armeabi-v7a x867. 在cmd中使用如下命令
C:\Users\baoyi.yang\Desktop\MyApplication\app\src\main\jni>ndk-build NDK_PROJECT
_PATH=. APP_BUILD_SCRIPT=./Android.mk NDK_APPLICATION_MK=./Application.mk
8. 编译
原文地址:https://www.cnblogs.com/gtgl/p/11268381.html
时间: 2024-10-14 02:48:41