安装 ndk 之前需要先安装 Android sdk 、ATD 之类的环境, 略。。。
1: 下载 Android ndk , 解压到 某一目录下
2: 阅读 ndk 目录下的 install.txt
IMPORTANT:
The Android NDK can only be used to target system images using
the Cupcake (1.5) or later releases of the platform.
This is due to subtle toolchain and ABI related changed that make
it incompatible with 1.0 and 1.1 system images.
The NDK requires GNU Make 3.81 or later being available on your development
system. Earlier versions of GNU Make might work but have not been tested.
You can check this by running 'make -v' from the command-line. The output
should look like:
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
...
On certain systems, GNU Make might be available through a different command like
'gmake' or 'gnumake'. For these systems, replace 'make' by the appropriate command
when invoking the NDK build system as described in the documentation. You might
also want to define the GNUMAKE environment variable to point to it.
The NDK also requires a Nawk or GNU Awk executable being available on your
development system. Note that the original 'awk' program doesn't implement
the 'match' and 'substr' functions used by the NDK build system.
II. Preparing your installation prebuilt cross-toolchain binaries:
------------------------------------------------------------------
Previous releases required you to run the 'build/host-setup.sh' script to
configure the NDK. However, this step has been removed in release 4 (a.k.a. r4).
The auto-detection and sanity checks that were performed by the script have
been moved into the NDK makefiles (and are now performed each time you invoke
GNU Make).
=========================
3: GNU Make 3.81 or later == gun make 版本 需要3.81 以上的
所以在安 装Cygwin的时候 , 选择1.7 以上的版本, 我选的最新的。
下载后运行Setup,点击next,选择Install from Internet:
然后下一步,选择适当的目录,
下一步,再选择相应的包的下载存放位置,默认,
下一步,网络配置,默认,
下一步,会搜索站点,下载站点选择台湾的,速度比较快,
等待其更新软件的列表后,就是比较关键的一步。
上面链接的文档和NDK附带文档中的INSTALL.TXT中也提到了,我们需要以下的工具:
1. GNU make
2. bash shell
3. Nawk或者GNU awk
所以在这里我们安装上面所需要的组件,找到Devel,并点击后面的循环箭头,将其改为Install
Devel中就包含了make及gcc等组件,可以点开前面的+号浏览。
然后找到Shell 选项,改为install
然后在上面的搜索框中搜索awk,找到两条,其默认已经包含了,这里确认一下,改为install。
next,开始安装。
安装完成后,找到Cygwin的安装目录下<cygwin>/home/<你的用户名>/.bash_profile文件,
如果该文件不存在, 先运行 一下 桌面创建的 cygwin 的快捷方式-即运行bash shell 运行后会自动创建
UltraEdit/Editplus打开,据说用记事本等的打开也会出问题。不要转换格式,否则出问题。最后一行,添加上
ANDROID_NDK_ROOT=d:/java/android-ndk-r4b-windows/android-ndk-r4b
export ANDROID_NDK_ROOT
其中的d:java/android-ndk-r4b-windows/android-ndk-r4b是我的安装的目录。改为你的。
保存退出。
桌面或者开始菜单打开Cygwin的bash shell,
界面如下,到这步之前,请确保你了解什么是Cygwin以及Cygwin是干什么的。
进入NDK的目录,
cd $ANDROID_NDK_ROOT
到此,NDK的配置就完毕了。
============================================
提示中有着么一句话:如果你不知道接下来干什么,请阅读docs目录下的OVERVIEW.txt。这个文档是非常有用,建议细读。
接下来是如何运行NDK中自带的samples。
首先还是在Cygwin的bash shell中:
cd $ANDROID_NDK_ROOT
make APP=hello-jni
此命令会在<ndk-dir>/apps/apps/hello-jni/project/libs/armeabi下生成.so文件,其实这个.so文件就相当于Windows下的dll。
然后,打开你配置好的Eclipse+ADT的环境。
新建Android Project。
新建选项中,选择create Project from existing source, 目录选择NDK下的hello-jni目录下的Project文件夹
这时,其Project的目录结构就很清晰咯~~~
然后编译运行,看到从.c文件返回的hello from JNI字符串:
over。