1.下载ndk20 for mac
https://developer.android.google.cn/ndk/downloads/index.html
2.配置ndk环境
# emacs /etc/profile
export PATH=~/android-ndk-r20:$PATH
3.在任意位置创建ndk-test目录
ndk-test
└── jni
├── Android.mk
├── Application.mk
└── test-ndk.c
<1>.Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test-ndk
LOCAL_SRC_FILES := test-ndk.c
LOCAL_ARM_MODE := arm
LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE
include $(BUILD_EXECUTABLE)
<2>.Application.mk
APP_PLATFORM := android-18
<3>.test-ndk.c
#include <stdio.h>
int main(){
int a = 3;
int b = 5;
printf(" Test Compile ndk-build Success!\n");
return 0;
}
4.编译运行
# cd ndk-test
# ndk-build
jni libs obj
# tree libs
libs
├── arm64-v8a
│ └── test-ndk
├── armeabi-v7a
│ └── test-ndk
├── x86
│ └── test-ndk
└── x86_64
└── test-ndk
# adb connect 127.0.0.1:62001
//push到夜神模拟器,注意夜神模拟器只支持x86 32位的
# adb push x86/test-ndk /system/bin
# test-ndk