您的位置:首页 > 移动开发 > Android开发

android ndk 的简单使用

2016-09-05 10:38 225 查看
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  的简单使用;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ndk android 原生