"Go" Windows environment build Android NDK Environment

Source: Internet
Author: User

Original URL: http://www.metsky.com/archives/525.html

The previous introduction of Windows under the Android development environment configuration, mainly for the Java development environment, for the only APK upper application developers, the basic enough, due to Linux system restrictions and Android packaging architecture limitations, many involved in the underlying devices, interfaces, Drive control application development, have to use the NDK development environment of this article (based on Android source code or kernel source code modification), development language use C/C++,NDK development closer to Linux development, need more about Linux application programming knowledge. This article introduces the NDK environment construction and basic programming ideas.

This article demonstrates the environment: Windows 7+CYGWIN+NDK R4.

Basic reading:

Build and configure Android development environment under Windows

Introduction to the Environment concept for Android development

Ubuntu under the NDK Environment Building method: Ubuntu under the NDK environment

First, download the Android NDK

You can download the NDK r4 for Windows or NDK R5 for Windows installation package:

Address: http://developer.android.com/sdk/ndk/index.html

After downloading, unzip to your working directory, for example: E:\Android\develop, results such as:

The Android NDK contains build, docs, samples, sources, Gnumakefile, Ndk-build, ndk-gdb, and readme content. Samples The following is a sample development demonstration project, first contact with the NDK development, it is recommended to start with examples. Let's look at the compilation environment configuration.

Second, download Cygwin

Since most of the NDK development involves compiling and running in the GCC environment, the Linux simulated compilation environment needs to be simulated in the Windows environment:

http://www.cygwin.com/

After the download is a Setup.exe file, the use of the following procedures:

The first step: Run the Setup program, the first step of the diagram, click Next directly to enter the next step.

The second step: Choose the installation method, the first time can be used direct connection online download installation, if there is an off-the-shelf offline package, you can choose to install offline (install from Local Directory).

The third step: Select the installation directory, such as C:\Cygwin, note that this directory refers to the Cygwin final installation directory, not the download file staging directory.

Fourth step: Set the local package staging path

The staging directory is placed in the Setup.exe sibling directory by default, and the downloaded name is similar to the ftp%3a%2f%2fcygwin.mirrors.pair.com%2f format.

Fifth step: Set up network connection mode

Sixth step: Select Download Site Address

At first try a few to see which speed to use which address (if you feel uncomfortable, click Cancel, again).

Seventh step: Wait for the loading of the installation item to load, select the installation item

We compile the NDK, in the default settings, just select Devel (click on devel in the list, change the following default to install, the arrow in the figure), and the others are the defaults.

Eighth step: Wait for the download to complete

Download completion time depends on the number of packages you choose and the network connection speed, for example, according to the default selection method of this article, it may take 4-5 hours, download the package about 750M, after the download is completed automatically installed to the installation directory set above.

Reminder: After the first download is completed, it is best to make a backup of the downloaded package directory, the next time you install the same environment can directly use the offline installation method (in the second step, select Local installation).

Third, verify the Cygwin environment

Once the installation is complete, run Cygwin once (Cygwin.bat) to create some user environment files and enter them separately:

Make-v

And

Gcc-v

If the test is successful, the make and GCC related version information is printed, such as.

Iv. Configuring NDK Path settings

You can modify it via vim in Cygwin, or you can modify home\< your user name >\.bash_profile file in the Windows installation directory to add the environment variable last

Ndk=/cygdrive/e/andriod/develop/android-ndk-r4

Export NDK

Which ndk=/cygdrive/< your drive letter >/<android ndk directory >, "NDK" the name casually up, often used not too long.

Restart Cygwin, enter:

CD $NDK

You can enter the NDK corresponding directory description settings OK.

V. Compiling and demonstrating the project

Now it's time to compile the relevant NDK project (some programs written in C + +) and compile the method as follows:

1. Under the Cygwin command line, go to the Android Project working directory:

CD $NDK

2. Enter the Samples\hello-jni directory, in turn (example of full path: E:\ANDRIOD\DEVELOP\ANDROID-NDK-R4\SAMPLES\HELLO-JNI)

3. Operation

$NDK/ndk-build

Note: the command $NDK and/ndk-build are connected together, there is no space in the middle, the actual use is to break into the full $ndk/ndk-build, do not just play ndk-build.

4. After the normal compilation, the corresponding. So file will be generated in your project Libs/armeabi directory.

Vi. importing static target libraries to Android projects

After compiling, you will get *.so static target library, you can import the project environment Eclipse Android Project to use, note that NDK programming is not necessarily to import this target library into Android project use, in addition to the use of the method described in this step, There are Android source code directly modified, compiled, and then burned to the development of the test machine, so that the application can be installed by default, power on the upgrade and so on more "thorough" function. To combine:

This step demonstrates the +andriod apk style belonging to the NDK Target library, in addition to the direct development of Android source code, direct compilation method (the exact point has played down the so-called engineering concept of Android, of course, source code development does not seem to be directly under Windows, It seems that the Linux family system must be used, and the days will be covered later in the article)

Use the following method (example):

1. Create a new project in eclipse the code in Hellojni,hellojni.java can refer to the NDK corresponding to the demo code under sample (android-ndk-r4\samples\hello-jni\tests\src\com \example \hellojni) Call method.

2. Copy the JNI and Libs folders under the NDK compilation project directory to the new project directory

Note that both folders are in the same directory as the SRC and res files in the project. Then go into Eclipse and refresh the project (you'll see two more folders).

3. Running the Eclipse project, you can see the output string in the HELLO-JNI.C function on the virtual machine.

4, follow-up you can try to modify the library source program or project Java program to familiarize with the NDK development process.

This article tags: android,java,eclipse,windows 7

This article link: http://www.metsky.com/archives/525.html

Copyright Notice: Original blog, reproduced and use please abide by the signature, non-commercial use and consistency, reproduced please indicate the source: Days Margin blog.

"Go" Windows environment build Android NDK Environment

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.