Ndk Development notes (I)-Environment setup

Source: Internet
Author: User

Install the ndk development environment:

1. InstallCygwin. To install GCC and other compilers, seeHttp://qichunren.javaeye.com/blog/214527

 

Result:

Run cygwin. In the displayed command line window, enter the cygcheck-C cygwin command to print the current cygwin version and running status. If the status is OK, cygwin runs normally.

Then input gcc-version, G ++ -- version, make-version, and GDB-version in sequence for testing. If both print the published version information and some description information, I am very happy to tell you, your cygwin installation is complete!

 

C:/cygwin/home/user name/. bash_profile

Add the following path.

 

Ndk =/cygdrive/ndk path

Path =$ {path}:/cygdrive/ndk path

Export ndk

 

Export ndk.

Configure the PATH environment variable.

 

 

2. Download ndkAndroid ndk (Native Development Kit)

 

Configure ndk Environment Variables

 

 

 

 

 

3. download the latest eclipse version

Http://www.eclipse.org/downloads/download.php? File =/Eclipse/downloads/drops/R-3.6.2-201102101200/eclipse-SDK-3.6.2-win32.zip

 

4. Configure the Android-related ADT and SDK Environment

 

 

4. Install CDT and support C/C ++ projects.

Http://www.eclipse.org/cdt/downloads.php

 

 

5. Configure eclipse

 

 

 

Project generation is fast and flexible. Have you ever used an eclipse generator? They are configurable switches used to execute your configured commands and refresh engineering resources. My configurations are as follows:

Right-click your project and select "properties"

Select "builders" in the list on the left"

Click "new..." on the right ..." Button

In the list box, select "program" as the configuration type. Click "OK" to go to the next configuration dialog box.

Name "Native builder"

Select "C:/cygwin/bin/bash.exe" as the location"

"Working directory" is "C:/cygwin/bin"

"Arguments" is:

-Login-c "CD/cygdrive/e/android-ndk-r5/samples/Hello-JNI & $ ndk/ndk-build"

 

Here/cygdrive/e/android-ndk-r5/samples/Hello-JNI is the directory for your project.

 

Make sure that there are two connection numbers before login, which are enclosed by quotation marks (-C.

Next, open the "refresh" tab:

Select refresh resources upon completion"

Select Specific resources"

Click "specify resources" and select the libs directory of your project.

Select "recursively include sub-Folders"

Next, open the "build options" tab:

Select "allocate console"

Select "launch in background"

Select "run the builder after a clean"

Select "run the builder during manual builds"

Select "run the builder during auto builds"

Select specify working set of relevant resources"

Click "specify resources", select the JNI directory of your project, and include all the files.

Click "OK.

The above red font must be correct. In this way, the BA

 

6. Test
Open the hello-jni.c file in the project JNI directory and prompt hello from JNI! Change it to another text, such as Hello World JNI., and then run your program in the die-mizer. If the simulator displays your latest modified text,

The following figure is displayed on the console ..

 

Gdbserver: [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver

Gdbsetup: libs/armeabi/GDB. Setup

Compile thumb: hello-JNI <= hello-jni.c

Sharedlibrary: libhello-jni.so

Install: libhello-jni.so => libs/armeabi/libhello-jni.so

 

 

So congratulations! You have configured all of them successfully.

 

 

7. Compile the. c file in JNI plus the following include file

 

Right-click your project and choose Properties --> C/C ++ Builder/settings/GCC compiler/include/to add the JNI header file you want to introduce.

Generally

Android-ndk-r5/platforms/Android-3/arch-arm/usr/include. It contains the JNI. h file.

In this way, you can use Alt +/in eclipse for inductive programming.

 

8. Android ndk logcat

To use logcat output in JNI, perform the following steps:

  • # Include <Android/log. h>
  • Local_ldlibs: =-llog is added to the Android. mk file. Otherwise, the following error is reported.
    undefined reference to `__android_log_write'
    Add the following command to log.
    __android_log_write(ANDROID_LOG_ERROR,"Tag","Message");
    You can view the definition of log. h file. Path:
    build/platforms/android-1.5/common/include/android/log.h

9. I create a new project, add the JNI and libs files, and follow the above steps to find that it cannot do step 7 above, right-click the project and choose properties. The properties --> C/C ++ Builder/option is not displayed. As a result, I cannot reference the C/C ++ header file, and the programming speed is seriously affected.

 

So I compared the difference between my test project and the hello-JNI project, and found that the hello-jin/. project document is different.

 

So compare the two project files in my project and add the following code to implement

 

Added the CDT control to buildspec.

Note that

$ {Workspace_loc:/test/debug} --> test is your project name.

<Buildcommand> <br/> <Name> Org. eclipse. CDT. managedbuilder. core. genmakebuilder </Name> <br/> <triggers> clean, full, incremental, </triggers> <br/> <arguments> <br/> <dictionary> <br/> <key>? Name? </Key> <br/> <value> </value> <br/> </dictionary> <br/> <key> Org. eclipse. CDT. make. core. append_environment </key> <br/> <value> true </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. autobuildtarget </key> <br/> <value> all </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. buildarguments </key> <br/> <value> </value> <br/> </dictionary> <br/> <key> Org. eclipse. CDT. make. core. buildcommand </key> <br/> <value> make </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. buildlocation </key> <br/> <value >$ {workspace_loc: /test/debug} </value> <br/> </dictionary> <br/> <key> Org. eclipse. CDT. make. core. cleanbuildtarget </key> <br/> <value> clean </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. contents </key> <br/> <value> Org. eclipse. CDT. make. core. activeconfigsettings </value> <br/> </dictionary> <br/> <key> Org. eclipse. CDT. make. core. enableautobuild </key> <br/> <value> false </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. enablecleanbuild </key> <br/> <value> true </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. enablefullbuild </key> <br/> <value> true </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. fullbuildtarget </key> <br/> <value> all </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. stoponerror </key> <br/> <value> true </value> <br/> </dictionary> <br/> <key> org. eclipse. CDT. make. core. usedefabuilbuildcmd </key> <br/> <value> true </value> <br/> </dictionary> <br/> </arguments> <br/> </buildcommand> <br/>

The CDT plug-in is added to the natures label.

 

<Natures> <br/> <nature> COM. android. IDE. eclipse. ADT. androidnature </nature> <br/> <nature> Org. eclipse. CDT. core. cnature </nature> <br/> <nature> Org. eclipse. CDT. core. ccnature </nature> <br/> <nature> Org. eclipse. CDT. managedbuilder. core. managedbuildnature </nature> <br/> <nature> Org. eclipse. CDT. managedbuilder. core. scannerconfignature </nature> <br/> <nature> Org. eclipse. jdt. core. javanature </nature> <br/> </natures> <br/>

 

Finally, add the C/C ++ project. the cproject file makes the project a C/C ++ project. copy the file directly from a C/C ++ project in eclipse to the root directory of your project, you can also observe the hello-JNI project.


 

After the modification, save OK to achieve the same effect as ndk smaple, making programming easier .. Pai_^

 

 

 

10. after the building is complete, it is best to do two projects, one is the C/C ++ project, the other is the android project, in the C/C ++ build, after the build, copy the libs/directory to the android project.


11. If you have any questions about the above steps, contact me.

 

Email: wongstar.iac@gmail.com

References:

Http://qichunren.javaeye.com/blog/214527

Http://blog.csdn.net/duduliao/archive/2011/02/11/6179511.aspx

Http://blog.csdn.net/lizhongkan/archive/2010/01/30/5271606.aspx

Http://www.rbgrn.net/content/348-get-your-eclipse-integrated-ndk-on

Http://blog.blackwhale.at/2009/08/android-ndk-logging/

Http://hi.baidu.com/justin8335/blog/item/8976de1d009e35f91ad5762e.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.