Android + Eclipse + NDK + cygwin preparation, androidndk

Source: Internet
Author: User

Android + Eclipse + NDK + cygwin preparation, androidndk

I used to take notes during NDK development. I hope it will be helpful to subsequent developers and will be available to you. If there is anything wrong, please leave it and throw bricks.

To facilitate android C ++ program development under Win32, we have made the following preparations:
1. Build an Android Development Environment

Download JDK
Download Eclipse
Download Android SDK
Download cygwin
Download android-ndk-r8

Install JDK and Eclipse first, start Eclipse, and install ADT

Install android development plug-in
(1) Open Eclipse and choose help> Install New SoftWare on the menu bar. The following page is displayed:

2. Download and install Android NDK
My NDK version is android-ndk-r8
Google's latest NDK for android-ndk-r8 is
Http://developer.android.com/sdk/ndk/index.html
3. Download and install cygwin
Since make and gcc must be used to compile the NDK code, you must first build a linux environment. cygwin is a unix simulation environment running on the windows platform.
It is very useful for learning unix/linux operating environments or porting applications from unix to windows. With it, you can use NDK to compile without installing linux.
Translate C and C ++ code. Next we will install cygwin step by step.
(I forgot it during installation)
First, you have to go to the http://www.cygwin.com to download setup.exe
1. Double-click "run". After running, you will see the Installation Wizard interface:
2. click Next.
In this case, select the installation method:
1) Install from Internet: Download the package directly from the Internet and Install it immediately (after the installation is complete, the downloaded package will not be deleted, but will still be retained so that the package can be installed again next time ).
2) Download Without Installing: Download the installation file to your local computer, but it is not installed yet.
3) Install from Local Directory: without downloading the installation file, Install it directly from a Local Directory containing the installation file.
3. Select the first item and click Next:
4. Select the directory to be installed. Note that it is best not to place it in a directory with Chinese characters and spaces, which may cause installation problems. Other options do not need to be changed. Next, click:
Step 5: select the cygwininstallation directory. This is the directory of the installation package you downloaded. Click Next To Run setup.exe:
6. At this time, you have three connection methods: the first one is OK by default;
1) Direct Connection: a Direct Connection.
2) Use IE5 Settings: Use the connection parameter Settings of IE to connect.
3) Use HTTP/FTP Proxy: Use HTTP or FTP Proxy Server for connection (you need to enter the server address and port number ). Based on your network connection status
Normally, select the first method, that is, the direct connection mode. Then
7. This is the site to be downloaded. By default, the first site is OK;
8. The installation package list will be downloaded.
9. Search allows you to enter the name of the package you want to download and quickly filter out the package you want to download. The four single-choice buttons select the style of the bottom tree. By default, they do not need to be moved. View Mo
To identify as Category, we recommend that you change it to full to show all the packages and check them again. Save some of the packages to be hidden. The check box in the lower left corner shows whether to hide the expired package. By default, the check box is checked.
Download the package we want to install. To avoid downloading it all, the following packages used for NDK development are listed: 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 more.
10. Choose to install these packages, click skip, and convert it to the digital version format. Make sure that the Bin item is converted to the cross sign, and the Src item is the source code. This is unnecessary.
11. Test whether cygwin has been installed.
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
The row is normal. Input gcc -- version, g ++ -- version, make-version, and gdb-version in sequence for testing.
Happy to tell you that your cygwin installation is complete!
4. Configure NDK Environment Variables
1. First find the installation directory of cygwin and find a home \ <your username> \. bash_profile file, if the installation directory is: D: \ cygwin (Note: My
There are no Trojans in the home folder. Solution: First open the environment variable, delete the HOME variable in the user variable, re-run cygwin, and automatically generate related files in the directory.
2. Open the bash_profile file and 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 future convenience, select a short name and save it.
3. Open cygwin and enter cd $ NDK. If the/cygdrive/d/DevTools/android-ndk-r8 information configured above is output, the environment variable setting is successful.
5. Use NDK to compile the program
1. Now let's compile a simple program with the installed NDK. Let's choose the built-in ndk example hello-jni, my location is D: \ DevTools \ android-ndk-r8 \ samples \ hello-jni
(Depending on your specific installation location ),
2. Run cygwin and enter the command cd/cygdrive/d/DevTools/android-ndk-r8/samples/hello-jni to enter the D: \ DevTools \ android-ndk-r8 \ samples \ hello-jni directory.
3. Enter $ NDK/ndk-build. After successful execution, it will automatically generate a libs directory and put the compiled. so file in it. ($ NDK is the environment variable that we configured before,
Ndk-build is the Compilation Program that calls ndk)
4. Go to the libs directory of hello-jni to check whether the. so file is generated. If yes, your ndk will run normally!
Note: If the/NDK-build: No such file or directory error occurs when $ ndk/ndk-build is executed, check that make.exe is available in the cygwin \ binfile. If not,
Click the setup file again, click View on the Select Packages page, enter make in Search, find the installation package of make, and click Next to install.
5. Create an ndk project and direct the directory to the corresponding directory (for ease of command line operations ). You can call the jni project quickly.
6. Use javah to compile the program
1. Use cmd to jump to the jni-related class with classes, open cmde.exe, and use the <drive letter:> to jump to the relevant directory.
2. Use javah to compile related class files to generate. h header files. Use-d to specify the location of the generated file. For example, if I store it in the jni folder of the e-drive project:
D: \ DevTools \ android-ndk-r8 \ samples \ hello-jni \ bin \ classes> javah-d: \ DevTools \ android-ndk-r8 \ samples \ hello-jni \ jni
Com. example. hellojni. HelloJni.

7. Use NDK In the Eclipse project

1) Create an android Project

 

2) Right-click the property Propeties-> builders-> [New]-> [Program]

Add cygwin installation path "D: \ cygwin \ bin \ bash.exe" in [Location], and enter "D: \ cygwin \ bin" in [Working Directory ", in [Argument], enter "-- login-c" cd/cygdrive/d/Workspace/Camera/jni & $ NDK/ndk-build ""

3) select [Refresh], click [Specify Resources], and select the folder [libs] in the project.

4) Right-click the property Propeties-> builders-> [New]-> [Program]

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

Select [Refresh], click [Specify Resources], and select the folder [libs] in the project.

6) Right-click the property Propeties-> builders-> [New]-> [Program]


How to configure NDK for cygwin

I put it in a folder under drive f, as defined in this way, NDK4CYRSTAX =/cygdrive/f/android_opencv_android_ndk4_crystax/android-ndk-r4-crystax
Export NDK4CYRSTAX
So you need to write it like this.
NDK_R7 =/cygdrive/c/ndk-android-r7
Export NDK_R7
Where c is your c drive, ndk-android-r7 is your NKD directory, note that the slash is different from the windows.

When developing android NDK, copy the so file generated by cygwin externally to lib/armeab in eclipse. Cannot it be packaged into the APK file?

It should be libs! Have you compiled the Anplication. mk file?

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.