首页 技术 正文
技术 2022年11月15日
0 收藏 466 点赞 3,052 浏览 2586 个字

分类: android2013-06-21
15:49 475人阅读 评论(0) 举报Android
NDK

目录(?)[-]

  1. System and Software Requirements

    1. Required development tools

本文将讲述内容如下:

1. 什么是NDK

2.什么时候要用NDK

3.NDK环境该如何搭建

1. 什么是NDK

NDK,我想应该是Native Development Kit的简称吧。NDK 提供了一系列的工具,

帮助开发者快速开发 C (或 C++ )的动态库,并能自动将 so 和java 应用一起打包

成 apk 。NDK 集成了交叉编译器,并提供了相应的 mk 文件隔离 CPU 、平台、 ABI

等差异,开发人员只需要简单修改 mk 文件(指出 “ 哪些文件需要编译 ” 、 “ 编译特性

要求 ” 等),就可以创建出 so 。

2.什么时候要用NDK

使用NDK,并不会给我们程序提高执行性能,反而会使程序复杂化。因此,尽量避免使用NDK,

除非你真的需要使用本地库(通常是C/C++库),不要因为擅长使用C/C++编程而使用NDK。

Android Framework提供了两种使用本地代码的方式 :

1.通过JNI调用本地代码

2.通过NativeActivity类调用本地代码(从2.3版本开始支持)

3.NDK环境该如何搭建

搜索网上各路资料,会发现都提到了安装Cygwin,以提供支持make 和 gcc的MinGNU环境。

就连官方的网站上,也是这么说:

http://developer.android.com/tools/sdk/ndk/index.html#Contents

System and Software Requirements

Required development tools

  • For all development platforms, GNU Make 3.81 or later is required. Earlier versions of GNU Make might work but have not been tested.
  • A recent version of awk (either GNU Awk or Nawk) is also required.
  • For Windows, Cygwin 1.7 or higher is required. The NDK will not work with Cygwin
    1.5 installations.

实际上,经过测试,在android-ndk-r8e-windows-x86.zip (
Revision 8e)的版本,就不需要

Cygwin环境了,我们只需要解压,在JNI的build.cm里指定好NDK引用的目录(或者通过ndk-build

去编译)就行了。

这把我坑的真够厉害的。。。。网上写的很多环境搭建指南都是基于比较旧的NDK版本。

Android developers官方居然也没更正过来。。。

顺便再网上找了下,终于找到了一点信息:( http://www.kuwanzu.net/xinwenzixun/xs/9876.html)

NDK能够让开发者在Android SDK的开发环境下进行native code的编译(即在Android中使用C++的代码)。

Windows下Android新版本的NDK使用非常便捷,不需要安装任何Cygwin之类的Linux环境工工具。

配置NDK开发环境:

1 确保已经安装好Android SDK和配置好开发环境。

2 下载Windows版本NDK,链接:zip

3 解压缩zip包到任意路径(例:d:\android-ndk)

4.配置环境变量。在path后增加d:\android-ndk(XP系统下:右键点击我的电脑->属性->高级->环境变量,

在系统变量中找到Path,在后面增加;d:\android-ndk)

经过以上步骤,NDK开发环境部署完毕。

NDK的使用:

将C++源码放入 <project>/jni/…
创建<project>/jni/Android.mk文件,文件中描述C++源码相关的编译配置
使用ndk-build命令进行编译: cd <project> ndk-build
通过SDK对工程进行编译,生成 .apk 文件.

The NDK includes a set of cross-toolchains (compilers, linkers, etc..) that can generate native ARM binaries
on Linux, OS X, and Windows (with Cygwin) platforms.

It provides a set of system headers for stable native APIs that are guaranteed to be supported in all later releases of the platform:

  • libc (C library) headers
  • libm (math library) headers
  • JNI interface headers
  • libz (Zlib compression) headers
  • liblog (Android logging) header
  • OpenGL ES 1.1 and OpenGL ES 2.0 (3D graphics libraries) headers
  • libjnigraphics (Pixel buffer access) header (for Android 2.2 and above).
  • A Minimal set of headers for C++ support
  • OpenSL ES native audio libraries
  • Android native application APIS

The NDK also provides a build system that lets you work efficiently with your sources, without having to

handle the toolchain/platform/CPU/ABI details. You create very short build files to describe which sources

to compile and which Android application will use them — the build system compiles the sources and places

the shared libraries directly in your application project.

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905