pico .bash_profile 注意要在根目錄下
java
export PATH=/Users/humax/Development/Homebrew/bin:$PATH:$M2_HOME/bin:/Users/humax/Development/Homebrew/opt/android-ndk
export ANDROID_NDK=/Users/humax/Development/Homebrew/opt/android-ndk
export ANDROID_NDKandroid
保存退出:
control+x
Y
回車bash
輸入ndk-build,驗證配置是否成功
app
出現上面的結果,表示配置成功,ndk-build要配合Application.mk,Android.mk使用gradle
ndk { abiFilters 'armeabi-v7a' }
env -> NewStringUTF是JNI提供的功能接口ui
注意:
Android.mk中spa
LOCAL_MODULE := hellondk LOCAL_SRC_FILES := liufeismart_com_hellondk_JNIUtil.cpp
Application.mk中code
APP_ABI := armeabi-v7a
注意,在調用idk-build以前,把jni目錄移動
在jni目錄下,執行ndk-buildblog
注意:在gradle中添加接口
android {
sourceSets { main.jniLibs.srcDirs = ['libs'] }
不然,
Process: liufeismart.com.hellondk, PID: 18436 java.lang.UnsatisfiedLinkError: Couldn't load hellondk from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/liufeismart.com.hellondk-2.apk"],nativeLibraryDirectories=[/data/app-lib/liufeismart.com.hellondk-2, /vendor/lib, /system/lib]]]: findLibrary returned null at java.lang.Runtime.loadLibrary(Runtime.java:358) at java.lang.System.loadLibrary(System.java:526)
Demo地址:連接: https://pan.baidu.com/s/1nuLkrQp 密碼: hig7