android studio下NDK开发
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
1、NDK 的下載 和 配置?
NDK 下載地址 :?https://developer.android.com/ndk/index.html? ?
NDK 配置 : ?ubuntu 下 : ? sudo gedit /etc/profile?
export NDK_HOME=/home/victor/android/android-ndk
export PATH=$NDK_HOME:$PATH
source etc/profile
2、android studio 配置NDK?
?項(xiàng)目右鍵--module setting - project structure-sdk Loaction - android Ndk location 配置下載后的ndk ?(解壓后)
3、NDK 開發(fā)?
? ? ? a、在項(xiàng)目目錄下新建一個(gè)java類 ?創(chuàng)建一個(gè)native方法?,如下。? ? ??
public class ParkJni {public native String getValueByKey(String key); }? b、build 項(xiàng)目?
? c 、../app/build/intermediates/classes/debug ?在這個(gè)目錄下就會(huì)有對(duì)應(yīng)的.clas文件?
? ? ? ? 轉(zhuǎn)到terminal ,?javah ?包名.ParkJni ?生成對(duì)應(yīng)的JNI文件 ? ? ? ? ? ? ? ? ? ? ? ? ? ?com_example_victor_permissiondemo_ParkJni.h
? d、在src/main目錄下新建jni文件夾,將com_example_victor_permissiondemo_ParkJni.h拷貝過去,
?e、在jni下新建隨意一個(gè)c文件 ,引入?com_example_victor_permissiondemo_ParkJni.h,并實(shí)現(xiàn)com_example_victor_permissiondemo_ParkJni.h中的方法 (com_example_victor_permissiondemo_ParkJni.h 中的方法仍是空方法,所以需要實(shí)現(xiàn))
?d、在build.gradle下的
defaultConfig 標(biāo)簽下 添加 ndk {moduleName "testJni" //生成的so名字abiFilters "armeabi", "armeabi-v7a", "x86" //輸出指定三種abi體系結(jié)構(gòu)下的so庫(kù),目前可有可無(wú)。 }e、重新編譯項(xiàng)目,在..app/build/intermediates下會(huì)多出ndk文件夾,目錄下會(huì)生成對(duì)應(yīng)的so庫(kù)。
4、NDK的使用
? ? ? 略。。
?
?
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
轉(zhuǎn)載于:https://my.oschina.net/u/559847/blog/681159
總結(jié)
以上是生活随笔為你收集整理的android studio下NDK开发的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Web Service概念梳理
- 下一篇: UNIX环境高级编程笔记之文件I/O