Sooner or later in your Android game development foray you may find
the need to have some code that runs faster. It turns out that Android
code written in C runs 10-100 times as fast as its Java counterpart. I
can verify this, as I've already moved a few major components in my
newest 3D game engine into native land. That's quite a boost but let's
face it - C is a pain in the ass and while Eclipse is great for Java,
it's not for C, right? Wrong. Here's how to set up a super speedy NDK
development environment.
First of all, Eclipse can do way more than just Java. Java is what
it's great at and what it was designed for but the architecture makes it
so that it can handle any language effectively, including C. There is a
component called CDT that allows for C/C++ Development in Eclipse. I'm
getting ahead of myself, though. Here's what you need:
Android NDK (Native Development Kit)
Eclipse CDT (C Development Tooling)
If you're in Windows, you'll need Cygwin
with the devel packages installed (Especially GCC and Make)
Here's what you need to do:
Install all 3 of those things. I like to install my NDK to
c:\Android_NDK. I'll refer to that dir for the rest of this article.
Get acquainted with the NDK. You need to configure each project as an
"app" in the c:\Android_NDK\apps dir. Just take a look at the examples.
They work and are thorough.
How to test your NDK:
Run cygwin
cd /cygdrive/c/Android_NDK
make APP=hello-jni
It should compile without errors. If you are missing GCC or Make or
any other dev packages, you will want to run your Cygwin setup again and
check to make sure that all of the development packages are installed.
If you have strange errors, I suggest reporting them in the NDK user's
group.
Once your NDK is working, you can add an app for your project and set
up the basic native framework for your project. Please refer to the
examples for this part. You will need a specific build file that tells
the compiler what sources to compile. JNI code is usually located in
your Android project's jni folder. A file called Android.mk will need
to be in there which instructs the compiler on what to compile.
After you get the basic configuration done, you will want to start
writing some C. NDK uses Java's standard JNI bindings to work. All of
the existing documentation on JNI should apply from this point forward.
What to code is beyond the scope of this article.
Now for the good part
If you've done any NDK work, you're probably used to using a text
editor or vim or some other editor to edit your C/CPP then running make
APP=myapp every time to build, then clicking refresh on your project in
Eclipse and then hoping that the shared object library file that gets
deployed is current. What a pain in the ass! There's a much, much
better way.
Now that you have CDT installed, you can edit all of your C/C++ right
from Eclipse. If you right click on a C/CPP source file, just pick
Open With--C/C++ Editor and it will use the CDT editor. Much nicer! It
won't be able to figure out what the code is doing because it's not
compiling it, but it will make editing nice and all in one spot.
Building is a snap as well. Ever used builders in Eclipse? They are
configurable triggers that will execute what you configure and refresh
resources for you. Make sure you know if you're on the old r3 NDK
(upgrade if you are - you should be on r4) and if so, I put different
instructions in this list for the different versions. Here's how I set
mine up:
Right click on your project, pick properties.
Select "builders" from the left-hand list.
Click "New..." on the right side.
Select "Program" as the configuration type.
I name mine "Native Builder"
Location - c:\cygwin\bin\bash.exe
Working Directory - c:\cygwin\bin
Arguments -
(for NDK r3):
--login -c "cd /cygdrive/c/Android_NDK && make APP=myapp"
(for NDK r4):
--login -c "cd /cygdrive/c/<myapp_project_dir> && /cygdrive/c/Android_NDK/ndk-build"
Make sure you have the two hyphens before login and the quotes after the hyphen-c
Now go to the refresh tab
Check "Refresh resources upon completion"
Select "Specific resources"
Click on the "Specify resources" button and select your project's lib directory.
Check "Recursively include sub-folders"
Now go to the build options tab
Check "Allocate Console"
Check "Launch in background"
Check "Run the builder After a Clean"
Check "Run the builder During manual builds"
Check "Run the builder During auto builds"
Check "Specify working set of relevant resources"
Click on "Specify Resources"
Select your project's JNI directory and all files within.
Now click OK on the bottom.
The assumption here is that cygwin is installed to c:\cygwin, NDK is
in c:\Android_NDK and your project is called "myapp". Change where
appropriate.
What did you just do?! You made it so that any time you edit any
files within your JNI directory and you save them, Eclipse will run the
NDK Builder for you via Cygwin and show the compile output in your
console. When it finishes, it will refresh your output (lib) directory
which will trigger ADT to compile a new APK for you and YOU ARE GOOD TO
GO!
This seriously sped me up while working on my current project. I hope you can all benefit from it!
分享到:
相关推荐
Eclipse集成Android NDK说明 1 2 为什么要用NDK? 2 3 为什么要集成? 2 4 怎样操作? 2 4.1 预备条件 2 4.1.1 Cygwin 2 4.1.2 Eclipse 2 4.1.3 Eclipse CDT 3 4.1.4 Android SDK 3 4.1.5 Android NDK 3 ...
"Eclipse集成Android NDK"这一主题涵盖了在Linux环境下使用Eclipse进行Android原生代码开发的关键步骤。Android NDK(Native Development Kit)是Google提供的一款工具集,允许开发者在Android应用中使用C和C++语言...
在Android应用开发中,Eclipse作为一个老牌的集成开发环境(IDE),虽然已经逐渐被Android Studio所取代,但在某些开发者的圈子里仍然有一定的使用群体。NDK(Native Development Kit)是Google提供的一个开发包,允许...
3. **Eclipse集成NDK开发** - **CDT插件**:CDT(C/C++ Development Tooling)是Eclipse中的一个插件,用于支持C/C++项目的开发。通过`Help -> Install New Software...`添加CDT的更新站点并安装。 - **导入NDK...
### 非常强大的Eclipse中Android NDK开发环境的配置说明 #### 一、概述 本文档将详细介绍如何在Eclipse中配置Android NDK开发环境,并实现C/C++代码的自动编译以及通过Eclipse使用Ant生成JNI所需的头文件。配置流程...
在Android开发过程中,Eclipse是一款曾经广泛使用的集成开发环境(IDE)。然而,随着Android Studio的兴起,Eclipse逐渐被取代,但在某些特定场景下,开发者可能仍需要使用Eclipse进行项目开发。本教程主要针对一个...
这个插件是专门为Eclipse设计的,用于集成NDK开发环境。在Eclipse中,如果没有这个插件,开发者将无法找到配置NDK的选项。安装了这个插件后,开发者可以在Eclipse内方便地管理NDK项目,进行编译、调试和构建原生代码...
### Eclipse 下 NDK 开发指南 #### 概述 本指南旨在为开发者提供关于如何在 Eclipse 开发环境中利用 Android NDK 进行开发的基础指导。Android NDK 是一套工具集,允许开发者使用 C 和 C++ 等原生代码语言来实现...
然而,有时候用户在Eclipse集成开发环境中可能会发现ADT(Android Developer Tools)插件没有提供NDK支持的选项,这可能阻碍了他们进行原生代码开发。 首先,我们需要理解Eclipse ADT和NDK的关系。ADT是Eclipse的一...
Eclipse是一款广泛使用的Java集成开发环境(IDE),但它的功能并不仅限于Java。通过添加插件和支持,Eclipse也可以用于Android的原生代码开发,这涉及到NDK(Native Development Kit)的配置。NDK是Google提供的一个...
而在Eclipse集成开发环境中进行NDK的配置与编译,则是一个重要的步骤。本文将详细介绍如何在Eclipse中配置NDK以实现SO库的自动编译。 #### 二、环境准备 1. **Eclipse IDE**:确保已经安装了Eclipse for Java ...
### Windows 下 Eclipse 集成 Cygwin 编译 Android NDK 在 Windows 环境下使用 Eclipse 开发 Android 应用时,如果需要利用 C 或 C++ 的功能,通常会涉及到 Android NDK 的使用。为了更好地整合开发流程,可以将 ...
通过集成NDK,开发者可以在同一个环境中进行Java和C/C++代码的编写,便于项目管理,提高开发效率。 **3. 怎样操作?** **3.1 预备条件** 在集成Android NDK到Eclipse之前,你需要准备以下组件: - **Cygwin**:...
Eclipse 集成 Android NDK 说明 1. 为什么要用 NDK? Android NDK (Native Development Kit) 是 Google 提供的一个工具集,允许开发者在 Android 应用程序中使用 C 和 C++ 代码。这主要是为了实现以下几个目的: ...
- **版本控制集成**:与Eclipse集成便于使用Git等版本控制系统管理代码。 ### 3. 怎样操作? #### 3.1 预备条件 - **Cygwin**:Windows用户需要安装Cygwin以提供Linux-like环境,因为NDK的构建工具链依赖于这些...
本文档主要介绍了如何在Windows 7操作系统上,使用Eclipse集成开发环境配置Cocos2d-x开发环境,使得开发者可以在同一环境中进行Java和C++代码的编写,无需借助其他编辑器如Visual Studio。以下是配置过程的详细步骤...
在Android开发领域,Eclipse和NDK是两个重要的工具,它们分别代表了IDE(集成开发环境)和原生开发工具套件。Eclipse是过去广泛使用的Android应用开发环境,而NDK则是Google提供的用于在Android平台上进行C/C++原生...