Welcome to reprint, reprint please indicate the source of http://blog.csdn.net/zengyangtech/article/details/7019350
Because Android requires a cross-compiling environment when there is a library at the underlying layer, C code needs to be compiled using ndk-build, while Java code needs to be compiled using Android SDK. Since I was not familiar with Eclipse IDE, C code is often written in Notepad during compilation, and then the ndk-Build Environment is built with cygwin, use ndk-build to compile the related so and then use eclipse to compile the Java program to use this so.
In fact, it is not so complicated. eclipse can fully compile so.
Click project> builders> New> program.
Then select location
In Windows
D: \ Android \ ndk \ ndk-r7-windows \ ndk-build.cmd
Executable ndk-build path in Linux and Mac
Then select
Working directory
D: \ Android \ ndk \ android-ndk-r6b \ samples \ <your JNI Project Name>
Select your corresponding JNI path. Then, when we compile and run this builder, The so library will be automatically compiled, and the SDK will compile the Java code, implement cross-compilation using eclipse
If you have any questions, read this article.
Http://mobilepearls.com/labs/ndk-builder-in-eclipse/
Mobile pearlslabssetting up automatic ndk builds in eclipsesetting 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 necessaryndk-build
Binary ):
Start by Right clicking on your android Project (namedHello-neonIn the below screenshots) with JNI resources, and selectProperties
. In the resulting dialog, chooseBuilders
Entry in the list to the left and pressNew...
Button:
A new dialog will open presenting a list of builder types. SelectProgram
Type and pressOK
Button:
InMain
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
Browse Workspace...
Button to select it graphically)
The result shoshould look something like the below:
Now continue with the refresh tab. Make sure the two checkboxesRefresh resources upon completion.
AndRecursively include sub-folders
Are checked. ChooseSpecific resources
Radio button and pressSpecify
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 pressFinish
Button:
Now skipEnvironment
Tab and go to the finalBuild Options
Tab. Make sureRun the builder: During auto builds
Checkbox is checked.
Since the ndk build only needs to happen when editing files injni
Folder, check that folder and pressFinish
Button.
Now finally pressOK
In the builder configuration dialog-the new ndk builder shocould now be up and running. Try editing any file injni
Folder and check thatConsole
View produces output from the build process:
Contact support@mobilepearls.com for feedback