欢迎转载,转载请注明出处http://blog.csdn.net/zengyangtech/article/details/7019350


由于做Android在底层有库的时候需要交叉编译环境,c代码需要用ndk-build来进行编译,而java代码则需要用Android sdk编译。之前由于对eclipse ide不太熟悉,所以往往编译的时候都是在记事本里写好c代码,然后用cygwin搭建ndk-build环境,用ndk-build来编译出相关的so之后再用eclipse里去编译java程序,从而使用该so。

其实并不用这么复杂,利用eclipse完全可以达到编译so的目的

点击project->builders->new->Program


然后选择Location

在windows下为

D:\Android\ndk\ndk\ndk-r7-windows\ndk-build.cmd

在linux和mac下为可执行的ndk-build路径

然后选择

Working Directory

D:\Android\ndk\ndk\android-ndk-r6b\samples\<your jni project name>

选择到您对应的jni路径,然后在我们编译运行的时候,这个builder就会自动地去编译so库,而sdk会去编译java代码,实现利用eclipse实现交叉编译


如果还有疑问,可以看这篇文章

http://mobilepearls.com/labs/ndk-builder-in-eclipse/

Mobile Pearls Labs Setting up Automatic NDK Builds in Eclipse

Setting up Automatic NDK Builds in Eclipse

When editing native JNI code in an Android project using theAndroid NDKyou may configure Eclipse to automatically rebuild your project when editing native code, just as it does for java. The below steps shows how to perform the necessary configuration (note that this requires revision 4 or later of the NDK - previous revisions does not contain the necessaryndk-buildbinary):

Start by right clicking on your android project (namedhello-neonin the below screenshots) with JNI resources, and selectProperties. In the resulting dialog, choose theBuildersentry in the list to the left and press theNew...button:

A new dialog will open presenting a list of builder types. Select theProgramtype and press theOKbutton:

In theMaintab, fill in the following:

Name:
NDK Builder
Location:
/opt/android-ndk/ndk-build (or wherever your ndk-build binary is). You may use a variable as in ${system_property:user.home}/lib/android-ndk/ndk-build
Working Directory:
${workspace_loc:/hello-neon} (replace hello-neon with your project name. Press the Browse Workspace...button to select it graphically)

The result should look something like the below:

Now continue with the refresh tab. Make sure the two checkboxesRefresh resources upon completion.andRecursively include sub-foldersare checked. Choose theSpecific resourcesradio button and press theSpecify Resources...button:

Since the ndk-build process will generate files in the lib folder, we want Eclipse to discover changes made there without having to refresh manually. So select the lib folder in the project (create one if necessary) and press theFinishbutton:

Now skip theEnvironmenttab and go to the finalBuild Optionstab. Make sure theRun the builder: During auto buildscheckbox is checked.

Since the NDK build only needs to happen when editing files in thejnifolder, check that folder and press theFinishbutton.

Now finally pressOKin the builder configuration dialog - the new NDK builder should now be up and running. Try editing any file in thejnifolder and check that theConsoleview produces output from the build process:

Contactsupport@mobilepearls.comfor feedback







更多相关文章

  1. android客户端xmpp & smack & openfire简单开发实例
  2. 安卓真机appium环境配置
  3. Android对文件的操作(简单的文件读取与写入)
  4. Android使用AnalogClock和DigitalClock
  5. PreferenceActivity用法简介
  6. Android(安卓)OpenGL ES: 第一个程序
  7. Android(安卓)aidl Binder框架浅析
  8. Android(安卓)Studio 第五十五期 - Studio3.0升级到gradle3.0.0
  9. Android支付宝沙箱环境使用教程

随机推荐

  1. Opengl ES系列学习--创建动态壁纸
  2. 一个同事的总结---防作弊。。。日后慢慢
  3. Android移动开发-添加手势以及识别用户手
  4. Android(安卓)物联网socket通信采坑
  5. android 系统核心机制binder(02)binder驱动
  6. Android(安卓)报错 - 无法解析类型 java.
  7. Android(安卓)4 通过 USB 连接扫描枪 获
  8. 对学Android的几点建议(磨砺营马剑威Andro
  9. Android常用名令集锦(图文并茂)(转:来自网
  10. 深入Android(安卓)【五】 ―― 任务和进