Compile and run the sample code that comes with ndk

Source: Internet
Author: User

 

Compile the so library in Windows

Preparations:

Ndk

Cygwin

Ndk can be used only in a C/C ++ compiling environment. Therefore, in windows, not only ndk needs to be installed, but also the corresponding C/C ++ environment, which is cygwin.

Ndk (search ndk directly in the SDK, the first is): http://developer.android.com/tools/sdk/ndk/index.html
Cygwin: http://www.cygwin.com/

After downloading the ndk directly, it is a compressed package, which can be directly decompressed.

The downloaded cygwinfile is a setup.exe. It must be installed online.

The following describes how to install cygwin.

After double-hitting setup.exe

 

Click next:

 

 

By default, select "Install from network". Next step:

 

 

Select the installation directory. Next step:

 

 

 

Next step:

 

 

Select direct connection. Next step:

 

 

Select the image address. The image address is 163. Next step:

 

 

This step is the most important. Select the content you want to install. Click devel install. You need to manually select:

Binutils
Gcc-core

Gcc-G ++
Gcc-mingw-core

Gcc-mingw-G ++
GDB

Make

 

You can use the default values for the others.

Alternatively, you can directly select all devel install items, that is, install all the items in Devel install.

Next, you just need to wait for the installation.

 

After both ndk and cygwin download and install, you get two things: I put them under the root directory of the E drive.

 

Next, open the E: \ cygwin \ home \ Administrator \. bash_profile file. You can use editplus

 

Append at the end of the file

Java code
 

  1. Android_ndk_root =/cygdrive/e/android-ndk-r8c
  2. Export android_ndk_root

Android_ndk_root =/cygdrive/e/android-ndk-r8c

Export android_ndk_root

 

 

Note: The e-generation table is an edisk, and I put it directly under the root directory. If you put it under a folder, remember to add the corresponding folder name.

Android_ndk_root can be another name, but note that this name is required during compilation! (Will be mentioned later)

 

 

The following is an example of self-contained code for compiling ndk:

Return to ndk, and there is a samples folder under the root directory of ndk, which contains some official code samples provided by Google. Let's take hello-neon as an example to demonstrate how to compile and run the built-in source code.

 

Open cygwin. bat in the cygwin directory

Go to the samples project directory and run the ndk-build command, for example:

 

 

Before performing this step, the project directory is as follows:

 

 

After compilation:

 

Next, import the project. Note that you cannot import the project through file-> inport. You need to import the project through file-> New-> Project-> Android project from existing code.

Imported Project Structure:

 

Run the project:

 

 

At this point, the ndk development environment has been successfully set up and the built-in code samples have been compiled and run successfully.

 

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.