http://mhandroid.wordpress.com/2011/01/23/using-eclipse-for-android-cc-development/

Programming in C/C++ on Android is just awesome! This tutorial shows how to setup Eclipse for using C/C++ together with Java in Android projects.

0) Prerequisities

You need to have Google ADT (Android Development Tools) installed. Seehttp://developer.android.com/sdk/eclipse-adt.htmlhow to do it.

You also need Android ndk. Download it fromhttp://developer.android.com/sdk/ndk/index.htmland unpack it somewhere.

1) Install CDT (C/C++ Development Tools) into Eclipse.

ChooseHelp->Install New Software…from the main menu.

Choosehttp://download.eclipse.org/releases/galileoas the source site. If you have another Eclipse release than Galileo choose the appropriate url.

Using Eclipse for Android C/C++ Development

ClickNext, Accept licences and finish the installation process.

2) In Eclipse create Android project to which you want to add C/C++ code (if you already don’t have one).

For this tutorial I’ve created simple MyAndroidProject.

3) In file manager createjni/directory in your project directory and place your C/C++ sources file here. Also put hereAndroid.mkfile which is a makefile that tells Android build-system how to build your files.

Take a look into Android ndkdocs/ANDROID-MK.htmlfile how to create one.

Simple example ofAndroid.mkfile:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_LDLIBS := -llog

LOCAL_MODULE := native
LOCAL_SRC_FILES := native.c

include $(BUILD_SHARED_LIBRARY)

4) Refresh (F5) directories inPackage Explorerto seejnidirectory here. Open your .c/.cpp file.

Your .c/.cpp file (native.cin my case) contains a lot of syntax errors which are not truly syntax errors. This is because Eclipse threats the project as a pure Java project. We have to convert the project into mixed Java & C/C++ project.

Using Eclipse for Android C/C++ Development


5) PressCtrl+n(or chooseFile->New->Other…from main menu) and selectConvert to a C/C++ Project.

Using Eclipse for Android C/C++ Development

This will convert your project into a mixed Java & C/C++ project rather than into pure C/C++ project (the name of the function is misleading).

ClickNext. Then choose your project and below chooseMakefile projectand– Other Toolchain –. ClickFinish.

Using Eclipse for Android C/C++ Development

After doing this Eclipse will ask you if you want to switch to C/C++ perspective. ChooseYesbecause otherwise you wouldn’t be able to set C/C++ build preferences.

6) Click on your project with right button and selectPropertiesor press Alt+Enter

Properties windows will appear. Here you have to configure use of ndk-build instead of make all command and set proper include paths.

7) ChooseC/C++ Buildand configurendk-buildas a build command

InBuilder settingsfillndk-buildintoBuild commandentry.You have to uncheckUse default build command. You also need to have ndk-build script in your PATH.

Using Eclipse for Android C/C++ Development

InBehavioursetting uncheckclean(ndk-build cleans project automatically on build and does not support separate clean command) and clear all text from build (ndk-builddoes not acceptallas a parameter.

Using Eclipse for Android C/C++ Development

ClickApplyto save settings.

8) ChooseC/C++ General->Paths and Symbolsand configure include path

InIncludestab chooseGNU CorGNU C++and clickAdd…button. Add path to include directory which is located inplatforms/android-4/arch/arm/usr/includesubdirectory of place where you’ve unpacked Android ndk. Include path depends on target for which you are compiling (android-4in my case — i.e. Android 1.6).

Using Eclipse for Android C/C++ Development

Finally clickApplyandOKand that is all. Now you can use all Eclipse power for editing your C/C++ sources. If you clickRunorDebugEclipse will compile C/C++ code as well as Java code and run it on device/emulator. However you will not be able to debug C/C++ code.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Mysql ALTER TABLE加字段的时候到底锁不
  2. 基于 Mysql 实现一个简易版搜索引擎
  3. MySQL的从库Seconds_Behind_Master延迟总
  4. MySQL数据库 Load Data 多种用法
  5. MySQL数据库Shell import_table数据导入
  6. Mysql数据库的主从同步配置
  7. Mysql实现简易版搜索引擎的示例代码
  8. 详细聊聊MySQL中慢SQL优化的方向
  9. MySQL8.0的WITH查询详情
  10. Prometheus 监控MySQL使用grafana展示