zoukankan      html  css  js  c++  java
  • 在eclipse里配置Android ndk环境 适用于windows mac 和linux(转)

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

    2012-02-27 13:02:16|  分类: android |  标签:java  program  android  |举报|字号 订阅

     
     
    原文:http://www.migantech.com/blog/codes/2011/11/28/%E5%9C%A8eclipse%E9%87%8C%E9%85%8D%E7%BD%AEandroid-ndk%E7%8E%AF%E5%A2%83-%E9%80%82%E7%94%A8%E4%BA%8Ewindows-mac-%E5%92%8Clinux/

    由于做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 dk dk dk-r7-windows dk-build.cmd

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

    然后选择

    Working Directory

    D:Android dk dkandroid-ndk-r6bsamples<your jni project name>

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

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

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

    Mobile PearlsLabsSetting up Automatic NDK Builds 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:

    Contact support@mobilepearls.com for feedback

  • 相关阅读:
    《JFlow: Practical Mostly-Static Information Flow Control》
    《嵌入式Linux C编程》第一章笔记
    Ansible --- 通过Ansible管理地区机房中的内网机器
    等保审核 --- MySQL密码复杂度
    等保审核 --- MySQL连接控制插件
    等保审核 --- MySQL操作审计记录
    CSS中居中的完全指南(中英对照翻译)
    svn提交报database is locked
    PHP session_cache_expire 会话函数
    MySQL CONCAT_WS 函数
  • 原文地址:https://www.cnblogs.com/tao560532/p/3894771.html
Copyright © 2011-2022 走看看