基于 Android NDK 的学习之旅-----序言

前些日子做了个Android项目, 引擎层 C, 准备写这个系类的文章,借此跟朋友来分享下我NDK开放的经验以及自己知识的总结和备忘。希望能给需要这方面资料的朋友提供一定的帮助。

主要涉及到:

  环境的搭建

Android.mk 文件的 配置

HelloWorld

NDK 打印信息

JNI 数据类型

Java 调用 C

C 调用 Java

数据的传输(基本数据类型的传输,引用数据类型的传输,数组的传输)

C中新建Java对象

Java方法在C中的映射(包括了签名的使用)

C中如何调用Java的方法(包括了静态的和非静态的)

JNI中资源的释放 等等

 

 

 

 

 

先详细介绍下NDK, JNI

 

What is the NDK?

   Google Say

The Android NDK is a toolset that lets you embed components that make use of native code in your Android applications.

Android applications run in the Dalvik virtual machine. The NDK allows you to implement parts of your applications using native-code languages such as C and C++. This can provide benefits to certain classes of applications, in the form of reuse of existing code and in some cases increased speed.

 

Android NDK是一个工具集合,让你嵌入组件,利用原生代码在你的Android Application

Android应用在虚拟机上执行.NDK允许你的应用通过原生代码如CC++去实现.这将给某些应用带来好处,这种方式能代码重用,并且在某些情况下提高执行速度】(个人翻译,翻译不准确的请指出)

 

 NDK全称:Native Development Kit

Android NDK 是配合 Android SDK 的工具,Google 推出NDK的目的不是为了取代Android SDK ,当然也不可能完全取代,它只是作为Android SDK  的一个补充。用来编译应用的原生代码。

  1NDK是一系列工具的集合。

  * NDK提供了一系列的工具,帮助开发者快速开发C(或C++)的动态库,并能自动将sojava应用一起打包成apk。这些工具对开发者的帮助是巨大的。

  * NDK集成了交叉编译器,并提供了相应的mk文件隔离CPU、平台、ABI等差异,开发人员只需要简单修改mk文件(指出哪些文件需要编译编译特性要求等),就可以创建出so

  * NDK可以自动地将soJava应用一起打包,极大地减轻了开发人员的打包工作。

  2NDK提供了一份稳定、功能有限的API头文件声明。

Google明确声明该API是稳定的,在后续所有版本中都稳定支持当前发布的API。从该版本的NDK中看出,这些API支持的功能非常有限,包含有:C标准库(libc)、标准数学库(libm)、压缩库(libz)、Log库(liblog)。

 

What is the JNI?

   Sun say

THE Java Native Interface (JNI) is a powerful feature of the Java platform.

Applications that use the JNI can incorporate native code written in programming languages such as C and C++, as well as code written in the Java programming language. The JNI allows programmers to take advantage of the power of the Java platform, without having to abandon their investments in legacy code. Because the JNI is a part of the Java platform, programmers can address interoperability issues once, and expect their solution to work with all implementations of the Java platform.

 

JNIJava Native Interface的缩写,中文为JAVA本地调用。从Java1.1开始,Java Native Interface(JNI)标准成为java平台的一部分,它允许Java代码和其他语言写的代码进行交互。JNI一开始是为了本地已编译语言,尤其是CC++而设计的,但是它并不妨碍你使用其他语言,只要调用约定受支持就可以了。

 

 

网络上相关的介绍资料太多了,我就不啰嗦了。嘎嘎

 

 

点击下载 常用文档:

NDK R5 Docs.rar

JNI Docs.rar


尽量一天一篇,下篇讲解 elipse sdk ndk cygwin cdt 环境的搭建


posted on 2011-08-12 14:06  陆晓峰  阅读(4759)  评论(10编辑  收藏  举报

导航