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开发,其实是为了项目需要调用底层的一些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 的简单使用;
相关文章推荐
- Android NDK——配置NDK及使用Android studio开发Hello JNI并简单打包so库
- Android之一个简单的NDK使用(二)
- Android 之NDK实战系列(3)——Android Studio下使用lame 进行简单的转换
- 使用Android-studio简单实现一个NDK的例子
- 第二章:Android之NDK配置与简单使用
- Android之一个简单的NDK使用(一)
- android studio JNI/NDK的简单使用
- 简单易懂的Android --NDK环境搭建>基础使用过程
- ubuntu搭建Android NDK环境与Android Studio简单使用NDK
- android 使用Eclipse开发NDK的配置和简单使用
- 【Android游戏开发二十一】Android os设备谎言分辨率的解决方案!以及简单阐述游戏引擎如何使用!
- 【Android游戏开发二十一】Android os设备谎言分辨率的解决方案!以及简单阐述游戏引擎如何使用!
- Android JNI学习之NDK_r5的使用简记(和r4之前有点区别)
- Android 使用NDK R5开发JNI应用详解
- Android 使用NDK R5开发JNI应用详解
- APIDemo学习笔记——Android上几种简单的Animation使用方法(一)
- Android 之 下拉框(Spinner)的简单使用
- Android中LocationManager的简单使用,获取当前位置
- 如何使用android的ndk建立native的开发环境
- Android提高十六篇之使用NDK把彩图转换灰度图