在eclipse中配置ndk builds的自動編輯環境

參考資料:http://mobilepearls.com/labs/ndk-builder-in-eclipse/


手動運行ndk-build太麻煩,能不能讓c像java那樣自動編譯呢?

當然可以,需要做以下配置:

1.新建一個項目編譯器

2.給編譯器命名,指定編譯工具(ndk-build.cmd)的路徑,指定被編譯的項目的路徑。(注意:window系統下的編譯器是ndk-build.cmd,linux下是ndk-build.)

3.給編譯器指定編譯完成所需要刷新的代碼的目錄;(lib/libs)

4.指定需要編譯的代碼所在的目錄;(jni)

5.編輯c代碼,保存,自動編譯,成功了;


具體介紹和圖解如下:

Setting up Automatic NDK Builds in Eclipse

1.新建一個項目編譯器

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:

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home

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

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home
2.給編譯器命名,指定編譯工具(ndk-build.cmd)的路徑,指定被編譯的項目的路徑。(注意:window系統下的編譯器是ndk-build.cmd,linux下是ndk-build.)
In theMaintab, fill in the following:
Name:NDK BuilderLocation:/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-buildWorking Directory:${workspace_loc:/hello-neon} (replace hello-neon with your project name. Press theBrowse Workspace...button to select it graphically)

The result should look something like the below:

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home
注意:window系統下的編譯器是ndk-build.cmd,linux下是ndk-build.


3.給編譯器指定編譯完成所需要刷新的代碼的目錄;(lib/libs)

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:

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home

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:

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home
4.指定需要編譯的代碼所在的目錄;(jni)

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

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home

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

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home
5.編輯c代碼,保存,自動編譯,成功了;

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:

在eclipse中配置android ndk的自動編譯環境builders - lockriver - Two PPs Web home
配置好之後,就會自動編譯了,……。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章