android NDK 环境搭建

来源:互联网 发布:主播猝死 知乎 编辑:程序博客网 时间:2024/05/16 23:42

NDK的版本选择

Here are the links for Windows, Mac and Linux. Latest revision of 11.x, 10.x, 9.x, 8.x and 7.x versions.

Android NDK r11c

Windows 32-bit | Windows 64-bit | Mac OS X 64-bit | Linux 64-bit

Android NDK r10e

Windows 32-bit | Windows 64-bit | Mac OS X 64-bit | Linux 64-bit

Android NDK r9d

Windows 32-bit | Windows 64-bit | Mac OS X 64-bit | Linux 64-bit

Android NDK r8e

Windows 32-bit | Windows 64-bit | Mac OS X 64-bit | Linux 64-bit

Android NDK r7c

Windows 32-bit | Mac OS X 64-bit | Linux 64-bit

看NDK Revision History, 可以看到一段说明
Android NDK, Revision 11 (March 2016)
NDK
Important announcements
The samples are no longer included in the NDK package. They are instead available on GitHub.
The documentation is no longer included in the NDK package. Instead, it is on the Android developer website.

r11以上版本,没有了本地的例子和文档,都指向线上的例子和文档,坑货…
我选择有本地例子和帮助的android-NDK最后版本 r10e的x86版本.
http://dl.google.com/android/ndk/android-ndk-r10e-windows-x86.exe

下载后的解压

下载后的android-ndk-r10e-windows-x86.exe, 双击解压,将解压后的目录剪切到d:\下.
D:\android-ndk-r10e 作为NDK安装目录.

按照帮助文档进行NDK设置

进入D:\android-ndk-r10e, 看README.TXT.
readme.txt说docs目录下有几个html.
进去一看,有一个changlog.html和Start_Here.html.
打开Start_Here.html, 按照说明来设置.
eclipse和ADT在android应用层开发时,已经设置好了,略过.

添加NDK环境变量

我的计算机是Win7X64.
将 D:\android-ndk-r10e 添加进环境变量.

配置eclipse, 指定NDK安装目录

Configuring Eclipse

Eclipse must know where the NDK is in order to use it when building your app.Follow these steps to set the location of the NDK:

Launch Eclipse, which is installed as part of the Android SDK.
Open Preferences.
In the pane on the left side of the Preferences window, select Android > NDK. The Android section expands, revealing a number of subsections.
Select NDK. In the pane on the right side of the Preferences window, browse to the directory that contains the NDK.
Click OK to return to the Package Explorer display.
这里写图片描述
这里写图片描述

验证NDK安装是否正确

Eclipse

To confirm that you have installed the NDK, set it up correctly, and properly configure Eclipse, follow these steps:

Import the hello-jni sample from `/samples/’, as you would any other Android project.
In the Project Explorer pane, right-click the project name (HelloJni). A context menu appears.
From the context menu, select Android Tools > Add Native Support, as shown in Figure 2. The Add Android Native Support window appears.

Accept the default library name (“hello-jni”), and click Finish.
Build and execute the application.
这里,按照手册上的说明进行验证还是有问题。可能是samples中工程本身有问题,编译没问题,在手机上跑起来崩溃.

自己来, 主要是看能否编译NDK的代码.

新建一个android工程, 调整为能正常在手机上跑的工程。
按照手册上说的, 在工程中添加NDK支持.
在cpp中,随便添加一段纯c++函数. 编译, 可以编译过,而且,在输出区可以看到.cpp被编译成了.so.
说明NDK在eclipse中能用了.
先不管是否由java代码来调用c++代码的事情, 运行这个添加了NDK支持的工程,跑在手机上是正常的.
这里写图片描述

用命令行来验证NDK编译是否正常

这里写图片描述

到此,NDK的环境搭建完成.
剩下的事情就是NDK的make文件的制作, linux程序编写, JNI函数的调用.

0 0
原创粉丝点击