Android + Eclipse + NDK + Cygwin compounding

Source: Internet
Author: User

In the past to do the development of the NDK notes, I hope that the successor to help, in the open to everyone to use, there is not the right place please stay, throw bricks can be.

To facilitate the development of Android C + + programs under Win32, we made the following configuration:
1, Android development environment to build

Download JDK
Download Eclipse
Download the Android SDK
Download Cygwin
Download ANDROID-NDK-R8

First install JDK, Eclipse, start Eclipse, install ADT

Install Android Development Plugin
(1) Open Eclipse and select Help->install New software on the menu bar to see the following interface:

2. Download and install Android NDK
I am using the NDK version for ANDROID-NDK-R8
The latest ndk from Google is ANDROID-NDK-R8
Http://developer.android.com/sdk/ndk/index.html
3. Download and install Cygwin
Since the NDK compiles code with make and GCC, you must first build a Linux environment, Cygwin is a UNIX simulation environment running on the Windows platform, which
is useful for learning unix/linux operating environments, or porting applications from UNIX to Windows. With it, you can use the NDK to edit without installing Linux
C, C + + code. Let's install Cygwin step-by-step.
(Forgotten when installing)
First, you have to go to http://www.cygwin.com to download setup.exe
1. Then double-click Run, and after running you will see the Installation Wizard interface:
2. Click Next
At this point you choose how to install:
1) Install from the Internet: downloaded directly from the Internet and installed immediately (after the installation is complete, the download of the installation files is not deleted, but is still retained for the next installation).
2) Download without installing: Just download the installation file locally, but not install it temporarily.
3) Install from the local directory: Do not download the installation files, directly from a locally containing the installation files to be installed.
3. Select the first item and click Next:
4, select the directory to install, note, it is best not to put in Chinese and white space in the directory, it seems to cause installation problems, other options do not change, then click Next:
5, the previous step is to choose to install Cygwin directory, this is to choose the directory where you download the installation package, the default is that you run the Setup.exe directory, directly click the next step:
6, at this time you have a total of three connection options: The default first is OK;
1) Direct Connection: Connect directly.
2) Use IE5 Settings: Connect using IE's connection parameter settings.
3) Use HTTP/FTP Proxy: Connect using HTTP or FTP Proxy server (you need to enter the server address, port number). The fact that users can connect according to their own network
To choose, generally under normal circumstances, all choose the first, that is, direct connection. And then
7, this is the choice to download the site, the default first is OK;
8. Download the list of load installation packages at this time
9, search is able to enter the name of the package you want to download, you can quickly filter out the package you want to download. The four radio buttons are the style of selecting the tree below, and by default it's OK to move. View Default
Recognized as category, it is recommended to change to full display all the package again, some of the province's bags are hidden away. The bottom left corner of the check box is whether to hide the expired package, the default tick, do not care about it on the line, the bottom open
Start by downloading the packages we want to install, and to avoid all downloads, here are the packages for developing NDK: autoconf2.1, automake1.10, Binutils, Gcc-core,
gcc-g++, Gcc4-core, gcc4-g++, GDB, Pcre, Pcre-devel, gawk, make a total of 12 packages, not less can only be more.
10, then start to choose to install these packages, point skip, turn it into a digital version format, to ensure that the bin item into a fork, and the SRC item is the source code, this is not necessary to choose.
11, the following test Cygwin is not already installed.
Run Cygwin, in the popup command line window input: Cygcheck-c Cygwin command, will print out the current Cygwin version and running state, if the status is OK, then Cygwin shipped
Line is normal. Then enter GCC--version,g++--version,make–version,gdb–version for testing, if you print out the version information and some descriptive information, very
Happy to tell you that your Cygwin installation is complete!
4. Configure NDK Environment variables
1, first find Cygwin installation directory, find a home\< your user name >\.bash_profile file, if the installation directory is: D:\cygwin, (note: I installed my
Home folder under the gods and horses are not, the solution: first open the environment variables, the user variables inside the home variable is deleted, re-run Cygwin, automatically generate the relevant files in the directory.
2. Open the Bash_profile file, add ndk=/cygdrive/< your drive letter >/<android NDK directory >
For example:
Ndk=/cygdrive/d/devtools/android-ndk-r8
Export NDK
The NDK name is random, for the convenience of later use, choose a short name, and then save
3, open Cygwin, enter the CD $NDK, if the output of the/CYGDRIVE/D/DEVTOOLS/ANDROID-NDK-R8 information configured above, it indicates that the environment variable setting is successful.
5. Use the NDK to compile the program
1, now we use the installed NDK to compile a simple program, we choose the NDK's own example Hello-jni, my location in D:\DevTools\android-ndk-r8\samples\hello-jni
(depending on your specific installation location),
2, run Cygwin, enter command Cd/cygdrive/d/devtools/android-ndk-r8/samples/hello-jni, enter to D:\DevTools\android-ndk-r8\samples\ Hello-jni directory.
3, input $ndk/ndk-build, after successful execution, it will automatically generate a libs directory, the compiled generated. so file inside. ($NDK is to invoke the environment variables we configured earlier,
Ndk-build is the build program that calls the NDK)
4, at this time to hello-jni the Libs directory to see if there are no generated. So files, if any, your NDK is functioning properly!
Note: If the execution $ndk/ndk-build appears/ndk-build:no such file or directory error, see if there is make.exe under Cygwin\bin, if not,
Re-click on the setup file, then click "View" on the "Select Packages" page, then enter make in search, find the Make installation package, then click Next to install OK.
5, create a new NDK project, the directory points to the corresponding directory (for easy command line operation). You can quickly complete the invocation of the JNI project.
6, using Javah to compile the program
1. Use CMD to jump to classes's JNI related class, open Cmde.exe, use < drive letter:> to jump to the relevant directory
2. Generate the. h header file using the Javah compilation-related class file. Use-D to specify where the makefile is placed. For example I am storing under the Jni folder of the E-drive project:
D:\devtools\android-ndk-r8\samples\hello-jni\bin\classes>javah-d D:\DevTools\android-ndk-r8\samples\ Hello-jni\jni
Com.example.hellojni.HelloJni.

7 , applying the NDK to eclipse projects

1), create Android Project

2), right-click Properties Propeties->builders->[new]->[program]

In [location] Add Cygwin installation path "D:\cygwin\bin\bash.exe", [Working Directory] Enter "D:\cygwin\bin", enter "Argument" in [--login-c] Cd/cygdrive/d/workspace/camera/jni && $NDK/ndk-build ""

3), select [Refresh], click "Specify Resources" and select the folder in the project [Libs]

4), right-click Properties Propeties->builders->[new]->[program]

5), add NDK path, click "New" to enter "NDK" and "/cygdrive/d/devtoolsandroid-ndk-r8"

Select the [Refresh] item, click "Specify Resources" and select the folder in the project [Libs]

6), right-click Properties Propeties->builders->[new]->[program]

Android + Eclipse + NDK + Cygwin compounding

Related Article

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.