Android开发者社区对JNI的呼声一直很高,这次Google发布NDK可以说是顺应民意。NDK和SDK一样提供了Linux、Windows、Mac三大开发平台的版本。
在Linux上,尤其是Debian/Ubuntu上进行安装,非常顺利,不会有什么问题。但是在Windows平台进行安装,就不那么轻松了,根据Google的建议,我们需要安装cygwin,而且特别提醒一定在安装时,注意把make和gcc包含进去。
For Windows, a recent release of Cygwin, including both the gmake and gcc packages, is required.
尽管如此,首次安装时,总是会遇到这样和那样的问题。由于没有经验,第一次安装,统统采用默认设置,由此遇到的第一个问题:
your C compiler doesn't seem to work:
gcc.exe: /temp/android-4068-test.c: No such file or directory
gcc.exe: no input files
根据错误信息,可以推定应该是安装cygwin时没有进行正确的设置,一番Google之后,找到答案,原来在安装时,要选择上make和gcc的 包选项,–这就是不看install.txt的后果,不过cygwin的安装界面实在让人看着别扭,我根本没有留意到可以选择包进行安装。
为了以防万一,遗漏掉依赖的包,干脆把Devel包从default变为install,这样这个包下所有内容一律安装。
安装之后,再尝试执行build/host-setup.sh,仍旧看到问题:
ERROR:
It seems you do not have the correct arm-eabi-4.2.1 toolchain binaries.
Please go to the official Android NDK web site and download the appropriate NDK package for your platform (windows).
See http://developer.android.com/sdk/index.html
又一番Google之后,在android-ndk的Google group上找到了答案:
When I explicit entered the following in my Cygwin shell environment
in file .bashrc it worked:
export ANDROID_NDK_ROOT=C:/Users/jonas/Android/android-ndk-1.5_r1
安装好NDK之后,最好花上几分钟读一读/docs目录下文档。特别是要完整阅读OVERVIEW.TXT,读完以后你就可以明白NDK的初衷以及如何使用它了。
- 把native source放在/sources/,当然也可以建立链接。
- 创建/sources//Android.mk,描述native sources。
- 创建/apps//Application.mk,描述Android applicaiton和navite sources。
- 在NDK路径的最顶极目录里执行make命令来build native code : make APP
- 最后,使用SDK工具,以通常的方式编译应用,SDK的build工具会将共享库打包进apk的文件。
NDK包含了两个示例应用,指明应该如何在你的应用使用native code,这里挑个简单的来看,hello-jni,一个简单的应用,从native方法中获取字符串,然后显示在应用的UI上。—这个native方法是在共享库实现。
一旦安装完NDK之后,就可以使用这些命令,从NDK的根目录下build共享库了:make APP=hello-jni 这将会编译/sources/samples/hello-jni/hello-jni.c,并输出共享库到/apps/hello-jni /project/libs/armeabi/libhello-jni.so.由于实际工作中,我们很少会把工程放在/apps下,因此下面将尝试如何 将应用和ndk分开来放置。
拷贝/apps/hello-jni/project,重命名为my-hello-jni,然后使用”Import from Existing Source”,创建名称为my-hello-jni的android工程。在/apps下新建文件夹my-hello-jni,并从hello-jni 下拷贝Application.mk到新文件夹下,打开该文件,修改APP_PROJECT_PATH为正确的路径,注意这里的路径应该是cygwin下 的路径,例如我的路径是:/cygdrive/e/workspace/my-hello-jni。
完成之后,到ndk的根路径下,执行make APP=my-hello-jni,然后即可成功看到结果:
Android NDK: Building for application 'my-hello-jni'
Compile thumb : hello-jni <= sources/samples/hello-jni/hello-jni.c
SharedLibrary : libhello-jni.so
Install : libhello-jni.so => /cygdrive/e/worskspace/my-hello-jni/libs/armeabi
相关推荐
新加坡人写的介绍Anroid上用ndk开发native应用的实例教程。全书以实例为纲,适合新手入门。压缩包中附带实例的源代码。
Android NDK is all about injecting high performance into your apps. Exploit the maximum power of these mobile devices using high-performance and portable code. This book will show you how to create C...
Beginning Android C++ Game Development introduces general and Android game developers like you to Android’s powerful Native Development Kit NDK The Android NDK platform allows you to build the most ...
From basic routines to advanced multimedia development, it helps you harness the full power of Android NDK. 附带: Developing_Multimedia_Applications_with_NDK Developing_Games_with_NDK
文件拆分、合并的Android NDK开发
Pro Android C++ with the NDK Native Development Kit) is an advanced tutorial and professional reference for today's more sophisticated app developers now porting, developing or employing C++ and ...
OVERVIEW OF THE ANDROID NATIVE DEVELOPMENT KIT
android开发有时需要开发c/c++插件,这就需要用到NDK(Native Development Kit),如果eclipse中没有配置NDK的选项则需要此插件。解压后对应放入eclipse目录下的features和plugins文件夹重启eclipse就可以看到NDK的...
Chapter 11: The Android Native Development Kit (NDK) Chapter 12: Publishing and Marketing Your Final Game Book Details Title: Beginning Android 3D Game Development Author: Robert Chin Length: 492 ...
Android NDK Game Development Cookbook A systematic guide consisting of over 70 recipes which focus on helping you build portable mobile games and aims to enhance your game development skills with ...
android-native-development-kit-cookbook
- Android Studio 2.1+ with [NDK](https://developer.android.com/ndk/) (>=r12) bundle. Screenshots ----------- A small extra view is toggled when a screen is touched. ![screenshot](screenshot.png) ...
尽管Android Studio已经越来越流行了,但很多人还是...NDK 是 Native Developmentit的缩写,是Google在Android开发中提供的一套用于快速创建native工程的一个工具。 使用这个工具可以很方便的编写和调试JNI的代码。 ND
android-sdk-NDK21.0.rar
NDK(Native Development Kit)是一种用于开发Android应用程序的工具集,它允许开发者使用C和C++等本地语言编写部分应用程序代码来实现更高性能和更底层的功能。 "NDK 12" 是指 Android NDK 的版本号为 12。Android...
android-ndk(android-ndk-r26b-windows.zip)适用于Windows系统
android native development android-ndk-01
android-sdk-NDK18.1.5063045.rar
在AndroidStudio下配置NDK,生成so文件的方法,依照示例即可