android ndk 的简单使用

1、why: 为啥学
  NDK开发,其实是为了项目需要调用底层的一些C/C++的一些东西;另外就是为了效率更加高些;
Android ndk 提供 了 opengls 
2、what
The NDK is a toolset that allows you to implement parts of your app using native-code languages such as C and C++. For certain types of apps, this can be helpful so you can reuse existing code libraries written in these languages, but most apps do not need the Android NDK.
NDK工具集,允许您使用本机代码实现 部分应用程序语言(比如C和c++。对于某些类型的应用程序,这可以帮助你可以重用现有代码库用这些语言编写的,但大多数应用程序不需要Android NDK;
3、how
    在androidstudio 使用ndk
a、下载ndk
在local.properties配置
ndk.dir=/Users/xiuer/android/android-sdk-macosx/ndk-bundle
sdk.dir=/Users/xiuer/android/android-sdk-macosx


b、新建一个javaclassndktest.JAVA
定义一个原生的方法:
Public native StringgetString();
在static方法内
static{
System.loadLibrary("hellow_jni");
}
这里的“hellow_jni”需要在build.gradle配置


defaultConfig{
applicationId"com.org.xiuer.androidlearningmanual"
minSdkVersion19
targetSdkVersion24
versionCode1
versionName"1.0"
//在这里配置


ndk{
moduleName='hellow_jni'
abiFilters"armeabi","armeabi-v7a","x86"
}


}






c、接着用c、c++实现我们在java类中指定的方法 
我们可以用命令javah生成头文件.h
app/创建jni目录,用来存放c或c++文件;


d、接着在activity里面调用java类里面本地的方法就可以了;






 这就是  ndk  的简单使用;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值