1. 至官方網站下載 ndk,並解壓縮至自訂資料夾
官方網址:http://developer.android.com/intl/zh-tw/ndk/downloads/index.html舉例路徑:Users/Peter/DevelopKit/NDK/
2. 打開 Terminal 命令终端,建立 bash_profile
- 一. 输入 pico .bash_profile
- 二. export NDK_ROOT=/Applications/Android-NDK/android-ndk-r10e
- 三. export PATH=$PATH:$NDK_ROOT
- 四. 最後儲存( control+X) 選 Y
3. 設定 Android Studio 外部工具:Android Studio → Preferences... → External Tools
-------------------------
新增 NDK Build
-------------------------
Name: NDK Build
Group: NDK
Description: NDK Build
Options: 全打勾
Show in: 全打勾
Tools Settings:
Program: NDK目錄/ndk-build
Parameters: NDK_PROJECT_PATH=$ModuleFileDir$/build/intermediates/ndk NDK_LIBS_OUT=$ModuleFileDir$/src/main/jniLibs NDK_APPLICATION_MK=$ModuleFileDir$/src/main/jni/Application.mk APP_BUILD_SCRIPT=$ModuleFileDir$/src/main/jni/Android.mk V=1
Working directory: $SourcepathEntry$
-------------------------新增 Javah-------------------------
Name: Javah
Group: NDK
Description: Javah
Options: 全打勾
Show in: 全打勾
Tools Settings:
Program: /usr/bin/javah (用 which javah 查詢目錄)
Parameters: -v -jni -d $ModuleFileDir$/src/main/jni $FileClass$
Working directory: $SourcepathEntry$
4.建立 MyHelloJni 專案
- Android Studio -> New Project : MyHelloJni
- 在 local.properties 增加:ndk.dir = NDK安裝目錄
- 在 build.gradle 增加:ndk {
moduleName
"JniTest"
} -
----------------------Android.mk
----------------------
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := JniTestLOCAL_SRC_FILES := JniTest.cinclude $(BUILD_SHARED_LIBRARY)
----------------------
Application.mk
----------------------
APP_ABI := all
----------------------
JniTest.c
----------------------#include <jni.h>#include "project_peter_com_myhellojni_MainActivity.h"
// JNICALL 呼叫自己專案的路徑方法,將 . 替換成 _JNIEXPORT jstring JNICALL Java_project_peter_com_myhellojni_MainActivity_getStringFromNative(JNIEnv *evn, jobject obj) {return (*evn)->NewStringUTF(evn,"Hello NDK demo");}
參考資料:
- hAndroid筆記: Android Studio + NDK + JNI
https://8085studio.wordpress.com/2015/04/25/android-studio-ndk-jni/ - Android 如何藉由JNI來使用C/C++程式? https://magiclen.org/android-jni/
Lucky Club Casino Site - Lucky Club
回覆刪除Lucky Club casino site. The site was created in 2006, luckyclub.live by the famous and respected Pragmatic Play company. Its main focus was on the quality of