Integrate ndk into eclipse

Source: Internet
Author: User

Preface

The most basic knowledge of the android method, see an article (http://www.rbgrn.net/content/348-get-your-eclipse-integrated-ndk-on) describes how to integrate Android ndk into eclipse, By the way it is translated.

Note:

Technical names are retained, such as cygwin
Eclipse (English version) does not translate the interface text, such as the button (specify resources ).
The content in the brackets is the comment I added.
 

 

Translated text:

In android game development, you will sooner or later find it necessary to run some code faster. Android code written in C is 10 ~ faster than the same Java version ~ 100 times. I can confirm this fact. In my latest 3D game engine, I use native programs (C/C ++ to write code) to some components, compiled to binary dynamic link library files.

This has brought about a huge performance improvement, but we have to face the fact that eclipse provides excellent support for Java Development, while developing C is extremely bad. Eclipse is not suitable for C development, right? The error shows you how to create a fast ndk development environment in eclipse.

First, declare that eclipse is not only suitable for developing Java applications. Eclilpse provides excellent support for Java development, and its original design is also for Java. However, thanks to its design architecture, eclipse can support development in any language including C language. A plug-in named CDT enables C/C ++ development in eclipse. Even though I have already mentioned it. The following are what you need:

Android ndk (Native Development Kit) http://developer.android.com/sdk/ndk/1.6_r1/index.html

Eclipse CDT (C Development tooling) http://www.eclipse.org/cdt/

If you are using a Windows operating system, you need to install cygwin and install important packages (especially GCC and make ).

The following steps are as follows:

Install the preceding three packages. I installed the ndk to C:/android_ndk. In the subsequent articles, I set this directory to the ndk installation directory by default.

To get familiar with ndk, You need to configure the "app" for each project in the C:/android_ndk/apps directory ". Like the examples in ndk, they can be correctly compiled and run, and require strict configuration.

How to test ndk:

Start cygwin

CD/cygdrive/C/android_ndk

Make APP = hello-JNI

Based on the above steps, you will be able to compile correctly. If GCC, make, or other development kits are missing from cygwin, you must reinstall cygwin and make sure all necessary Development Kits are installed. If you encounter any special errors, we recommend that you report these errors to the ndk user group.

Once the ndk works properly, you can add and configure your ndk development project. Like example of ndk, you need a detailed Build File (Android. mk), which tells the ndk compiler what file to compile. The JNI code file is usually placed in the JNI folder of the application project. The android. mk file in this directory guides the ndk compiler to compile programs.

After completing these basic configurations, you will want to write C code. Ndk is implemented using java standard JNI technology. A large number of JNI documents are applicable here. How to Write JNI code is beyond the scope of this article.

The following is a useful part:

If you have developed an ndk program, you may be accustomed to using a text editor or Vim to edit your C/C ++ code, and then use the make APP = MyApp command to compile it, click "Update Project" in eclipse, and finally look forward to the latest shared libraries deployed. What a pain! In fact, there is a better way.

Now that you have installed CDT, You can compile your C/C ++ file in eclipse. Right-click the C/C ++ source file and choose to open it in the C/C ++ editor to use the CDT compiler. More friendly! Because the C/C ++ source file has not been compiled, you do not know whether the code is correct or not. But this also makes it easier for you to edit the code on an interface.

Project generation is fast and flexible. Have you ever used an eclipse generator? They are configurable switches used to execute your configured commands and refresh engineering resources. My configurations are as follows:

Right-click your project and select "properties"

Select "builders" in the list on the left"

Click "new..." on the right ..." Button

In the list box, select "program" as the configuration type. Click "OK" to go to the next configuration dialog box.

Name "Native builder"

Select "C:/cygwin/bin/bash.exe" as the location"

"Working directory" is "C:/cygwin/bin"

"Arguments" is:

-- Login-C "CD/cygdrive/C/android_ndk & make APP = MyApp"

Make sure that there are two connection numbers before login, which are enclosed by quotation marks (-C.

Next, open the "refresh" tab:

Select refresh resources upon completion"

Select Specific resources"

Click "specify resources" and select the lib directory of your project.

Select "recursively include sub-Folders"

Next, open the "build options" tab:

Select "allocate console"

Select "launch in background"

Select "run the builder after a clean"

Select "run the builder during manual builds"

Select "run the builder during auto builds"

Select specify working set of relevant resources"

Click "specify resources", select the JNI directory of your project, and include all the files.

Click "OK.

Assume that cygwin is installed in C:/cygwin; ndk is installed in C:/android_ndk; The project name is "MyApp ". Replace these parameters accordingly based on your installation configuration.

What have you just done? Every time you modify any file in the JNI directory, eclipse automatically starts ndk to compile your project through cygwin and outputs the compilation information on the console. After compilation, the project output directory (LIB) is automatically refreshed and the ADT is triggered to generate a new APK installation package. All of this is extremely simple.

Integrating ndk into eclipse actually accelerates the development progress of my current project. We hope you will benefit from this in the text.

 

 

Postscript:

The steps to integrate ndk into eclipse are relatively simple. The authors of this article are more "cool" (most authors in the United States have such preferences), but it looks even more interesting!
It is not easy to do translation for the first time, and it is often necessary to repeat it. This article is not very difficult, but it should be a good start. In the future, more efforts should be made to exercise in writing, English, and reading.

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/lizhongkan/archive/2010/01/30/5271606.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.