Ndk Development Environment build _ R8

Source: Internet
Author: User

Main content of this article:

1. Install Android ndk

2. Install cygwin and use ndk to compile

3. Integrate C/C ++ Development Environment CDT in eclipse

4. Install the Sequoyah plug-in.

5. JNI compiling environment Configuration

 

This article is based on the android development environment. The basic environment must include at least the following:

1. JDK

2. Eclipse

3. Android SDK and ADT

Refer to my previous "android Development Environment setup ".

I. Android ndk installation and configuration

Download Android ndk. : Http://developer.android.com/tools/sdk/ndk/index.html

Download and decompress it to your working directory, such as: D: \ Java \ android-ndk-r8, the result is as follows:

 

Note: samples contains several instance development demonstration projects. We recommend that you start with the example for the first time.

It is a technical document in docs, which can be studied with strong English proficiency.

Ii. Install cygwin and compile with ndk

Most ndk development involves compiling and running C/C ++ in the GCC environment. Therefore, cygwin must be used to simulate the Linux compiling environment in the Windows environment.

Download:

Cygwin: http://www.cygwin.com/

Click setup.exe in the upper right corner to download the file.

Installation:

Step 1: run the setup.exe program and click Next to go to the next step.

Step 2: select the installation method. For the first time, you can use direct connection to download and install the package online. If you have a ready-made offline package, you can select offline installation (install from local directory ).

Step 3: select the installation directory. For example, D: \ Java \ cygwin. Note that this directory is the final installation directory of cygwin, not the temporary directory for downloading files.

Step 4: set the path for saving local packages. The temporary directory is stored in the same directory of setup.exe. It is recommended to put it in a specified folder, such as D: \ cygwin_install_file. After the installation is complete, package and back up the folder. You do not need to download the folder again later.

Step 5: Set the network connection mode. The crab hasn't crawled yet. Select the first one.

Step 6: select the download site address. It is said that the speed of 163 sites in China is good, and I also use this.

Step 7: Wait for the loaded installation item to load and select the installation item. Click devel-default to change it to devel-install. After expansion, you can see that the subitem under it has been selected. (In most online tutorials, we have selected 12 packages, which is too difficult to find, download all the files directly. Select about MB for all files ). No other settings are required on this interface.

Step 8: wait until the download is complete. The download completion time depends on the number of installation packages you select and the network connection speed. The version I installed is about 983 MB. After the download is complete, it will be automatically installed in the installation directory set above, installation also takes a long time, so there is no problem if you have a meal.

Reminder: We recommend that you back up data in step 4. If there is a backup, select offline installation in step 2.

Verification:

Run "cygwin. Bat" in the installation directory. When it is run for the first time, it automatically creates user information, which is stored in ". \ cygwin \ home.

Run "cygwin. in the bat 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.

Enter the "make-V" and "gcc-V" commands respectively. If the check succeeds, make and GCC versions will be printed out.

Set the ndk path:

Add the ndk path to the Windows system environment variable. Using a Linux-style path like/cygdrive/D/Java/android-ndk-r8, cygwin issues a warning when compiling with D: \ Java \ android-ndk-r8 under windows.

 

Run the cygwin command line. You can directly use this environment variable, or manually run CD to this directory:

 

Compile the program using ndk:

Now we use the installed ndk to compile a sample program provided by ndk hello-JNI (my directory is located at: D: \ Java \ android-ndk-r8 \ samples \ hello-JNI ).

Step 1: Run cygwin. After configuring the environment variable, enter "CD $ ndk/samples/Hello-JNI /", if not configured, enter the command CD/cygdrive/D/Java/android-ndk-r8/samples/Hello-JNI to enter the hello-JNI project directory.

 

Step 2: compile. Run the "$ ndk/ndk-build" command to compile the SDK. Ndk-build is the Compilation Program that calls ndk.

I have not encountered the following errors, but my predecessors have summarized them as follows:

Error: Android ndk: Host 'awk' tool is outdated.

Solution: Open the Directory D: \ Java \ android-ndk-r8 \ prebuilt \ windows \ bin \ partition and delete awk.exe (back up for the sake of insurance ).

 

Step 3: go "... /Hello-JNI/libs/armeabi "directory to check whether the. So file is generated. If yes, your ndk will run normally!

 

Import the hello-JNI sample of ndk to eclipse:

Step 1: Create a new Android project hellojni in eclipse. Select "Create project from existing source" when creating Android project, and enter "D: \ Java \ android-ndk-r8 \ samples \ hello-JNI" in location (note: when selecting API level, You must select version 1.5 or higher ).

Step 2: run Android aplication directly. Note that you must compile the hello-JNI file and generate the. So file before using ndk to compile the program.

 

3. Integrate C/C ++ Development Environment CDT in eclipse

The installation of CDT allows us to develop C/C ++-based native code and Java-based shells at the same time in a project, the subsequent configuration allows you to Compile two pieces of code at a time.

Download:

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

Note:

Eclipse C/C ++ ide indigo Sr2: it is an eclipse development environment with CDT.

P2 software Repository: Online installation address. (Seems to have been crawled by a crab)

Cdt-master-8.0.2.zip: This is the offline installation package for CDT. (We recommend that you use this feature to retain offline packages and reuse them)

Offline installation:

Eclipse-> help-> install new software, and click Add. Name: Random. We recommend that you use the "CDT _ version ". Location: Click archiveto locate the downloaded cdt-master-8.0.2.zip file.

Error:

If the "Duplicate location" error occurs below the location, go to window-> preferences-> install/update-> avaliable software site to find the error and remove it.

Verification:

After the installation is complete, create a new project in eclispe. If the C/C ++ project appears, it indicates that the CDT plug-in is successfully installed.

 

4. Install the Sequoyah plug-in

The Sequoyah plugin is used to set native development support for Android projects.

Official Website:Http://www.eclipse.org/sequoyah/downloads/

Online installation:

The official website provides the Update site address and installation package for online installation. It seems that the installation package is more than 1 MB, online installation is not crawled by crab, and it is directly installed online. Select all the installable items listed in the List and complete the installation.

Location: http://download.eclipse.org/sequoyah/updates/2.0/

 

Note:

On the installation page, do not select the "Group items by category" check box. The check box is selected by default, and the list is empty (there are no categorized items.

 

Configuration:

After the Sequoyah plug-in is installed, configure the ndk path for Android.

Add the ndk path in "window-> preferences-> Android-> Local Development.

 

Verification:

Right-click the previously created "hellojni" project and choose "add native support…" in the "android Tools" option ..." Option is successful.

V. JNI compiling environment Configuration

Still taking the previously created "hellojni" as an example, until now, if we modify the "/hellojni/JNI/hello-jni.c" file, the dynamic link library libhello-jni.so file will not be recompiled. This is because we did not add the required compilation configuration and dependency Library to the JNI project. Now let's configure it.

Step 1: Switch the project. Click File> New> Other (shortcut: Ctrl + n ). Select "convert to a C/C ++ Project (adds C/C ++ nature)" under "C/C ++ )". Go to "Next ".

 

Step 2: Select the "hellojni" project you just created. Select "makefile project" on the left and "cygwin GCC" on the right ". The "Perspective" prompted after confirmation is not clear. Click "yes.

 

Step 3: Right-click the "hellojni" project and select "properties ". Configure "C/C ++ build" and "C/C ++ general-> paths and symbols ".

C/C ++ build: click "C/C ++ build" and remove the "use default build command" check box selected by default in "Builder Settings" on the right. Set build command to bash D: \ Java \ android-ndk-r8 \ ndk-build ".

C/C ++ general-> paths and symbols: Add a new gnu c dependency path under the nodes. This "hellojni" project requires "D: \ Java \ android-ndk-r8 \ platforms \ Android-8 \ arch-Arm \ USR \ include", and then select different dependent libraries based on different projects.

 

Verification:

Replace the string "hello from JNI!" in "/hellojni/JNI/hello-jni.c !" For example, "Hello JNI from Baron !", If the character string output on the simulator changes after running, the configuration is successful.

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.