在eclipse里配置Android ndk环境 适用于windows mac 和linux[转]

简介:

由于做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/

 

Setting up Automatic NDK Builds in Eclipse

When editing native JNI code in an Android project using the Android NDK you 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 necessary ndk-build binary):

Start by right clicking on your android project (named hello-neon in the below screenshots) with JNI resources, and select Properties. In the resulting dialog, choose the Builders entry in the list to the left and press the New... button:

A new dialog will open presenting a list of builder types. Select the Program type and press the OK button:

In the Main tab, 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 checkboxes Refresh resources upon completion. and Recursively include sub-foldersare checked. Choose the Specific resources radio button and press the Specify 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 the Finish button:

Now skip the Environment tab and go to the final Build Options tab. Make sure the Run the builder: During auto builds checkbox is checked.

Since the NDK build only needs to happen when editing files in the jni folder, check that folder and press the Finish button.

Now finally press OK in the builder configuration dialog - the new NDK builder should now be up and running. Try editing any file in the jni folder and check that the Console view produces output from the build process:

 
from:http://blog.csdn.net/zengyangtech/article/details/7019350
欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 572064792 | Nodejs:329118122 做人要厚道,转载请注明出处!
















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/sunshine-anycall/p/3391438.html ,如需转载请自行联系原作者


相关文章
|
28天前
|
安全 Unix Linux
Metasploit Pro 4.22.7-2025052201 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.7-2025052201 (Linux, Windows) - 专业渗透测试框架
48 5
Metasploit Pro 4.22.7-2025052201 (Linux, Windows) - 专业渗透测试框架
|
1月前
|
安全 前端开发 Linux
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
67 3
Immunity CANVAS Professional 7.27 (macOS, Linux, Windows) - 渗透测试和漏洞利用平台
|
1月前
|
安全 测试技术 Linux
Flawnter 5.9.1 (macOS, Linux, Windows) - 应用程序安全测试软件
Flawnter 5.9.1 (macOS, Linux, Windows) - 应用程序安全测试软件
78 2
Flawnter 5.9.1 (macOS, Linux, Windows) - 应用程序安全测试软件
|
1月前
|
安全 Unix Linux
Nexpose 8.7.0 for Linux & Windows - 漏洞扫描
Nexpose 8.7.0 for Linux & Windows - 漏洞扫描
52 4
Nexpose 8.7.0 for Linux & Windows - 漏洞扫描
|
13天前
|
NoSQL IDE MongoDB
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
71 0
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
23天前
|
存储 安全 Ubuntu
从Linux到Windows:阿里云服务器系统镜像适配场景与选择参考
阿里云为用户提供了丰富多样的服务器操作系统选择,以满足不同场景下的应用需求。目前,云服务器的操作系统镜像主要分为公共镜像、自定义镜像、共享镜像、镜像市场和社区镜像五大类。以下是对这些镜像类型的详细介绍及选择云服务器系统时需要考虑的因素,以供参考。
|
1月前
|
关系型数据库 MySQL Java
安装和配置JDK、Tomcat、MySQL环境,以及如何在Linux下更改后端端口。
遵循这些步骤,你可以顺利完成JDK、Tomcat、MySQL环境的安装和配置,并在Linux下更改后端端口。祝你顺利!
132 11
|
30天前
|
SQL 安全 Linux
Nexpose 8.8.0 for Linux & Windows - 漏洞扫描
Nexpose 8.8.0 for Linux & Windows - 漏洞扫描
34 0
Nexpose 8.8.0 for Linux & Windows - 漏洞扫描