Use Android * x86 NDK for Eclipse * and transplant the NDK Sample Application

Source: Internet
Author: User

Target

Android plug-in for Eclipse (ADT) now supports NDK-based application development. It can automatically generate project and component files and code stubs, and can be integrated into the entire Android Application Development (build the native library, copy the Library to the corresponding JNI folder in the project, package the application, and generate the final APK with the NDK code ). This article will discuss how to configure Eclipse to take advantage of this function and demonstrate examples of porting NDK applications.

Configure the Eclipse ADT plug-in for use with NDK

You must configure the Eclipse ADT plug-in to point to the NDK installation path before using this new function. First, update the ADT plug-in Eclipse to get the latest changes and download the latest NDK from the following website:

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

In Eclipse, choose Window> preferences> Android> NDK. Enter the NDK installation path as follows (Here we assume that you have downloaded the NDK to c: \ sw \ android-ndk on Windows *) and click "application ", click OK ".


Figure 1: NDK configuration in Eclipse Android ADT plug-in

Now we should enable and activate NDK-related functions in Eclipse ADT. Let's open an ndk jni example and build it.

Open the hello-jni sample NDK application in Eclipse and add the NDK build support to the project.

To build native ndk jni examples in Eclipse, we need to let Eclipse ADT understand that this example uses native/NDK code.

Let's first import the HelloJni example to eclipse. Open "file"> "new"> "project"> Android> "Android project from existing code" in Eclipse ". On the next screen, enter the path of the hello-jni sample project (provided in the NDK installation folder), select the "Copy to work zone" check box, and then click "finish ". Use the HelloJni path from your NDK installation folder to replace the root directory path.


Figure 2: import the sample HelloJni project to Eclipse

Because x86 Android NDK supports Gingerbread * and a higher Android platform, we need to ensure that the minimum and target SDK configurations in the application description file are updated. Open AndroidManifest. xml in the HelloJni example in Eclipse. Click "use SDK" in the AndroidManifest editor and check whether the minimum SDK is set to 10 (API 10 ).


Figure 3: description file editor in Eclipse

We are now ready to add NDK build support to this project in Eclipse. In Eclipse, right-click the hello-jni Project (com. example. hellojni. HelloJni)-> Android tool-> Add Native support-> complete.


Figure 4: Add NDK support to projects in Eclipse

This will update the project configuration using settings related to the ndk component. When we re-build the project, it will first compile and build the NDK code, copy the built library to the corresponding project folder, and then continue the general APK build process.

Build and run applications in the simulator

Continue building the application and run it in the Android simulator. Assume that Gingerbread x86 AVD has been run on the HAXM-based Android simulator.

In Eclipse, right-click the hello-jni Project (com. example. hellojni. HelloJni)-> Run as-> Android Application. Eclipse should automatically recreate the project and try to deploy/run the APK on the simulator.

However, when the simulator is running, we see the following error message, because the default NDK Project Settings do not support x86.


Figure 5: run the sample application in the simulator

In Eclipse, you can see that the logcat error "hello-jni cannot be loaded" is displayed"


Figure 6: Logcat shows that the native library cannot be loaded

By default, NDK build does not automatically build x86 ABI. We will need to create the component File "Application. mk" to clearly specify our build objectives, or pass the command line parameters into the NDK build command.

Port the application to use the x86 ABI and NDK build files

We can modify the Project to Support x86 ABI. In Eclipse, right-click the "jni" folder in the hello-jni project, and choose "New"> "file"> set "Application. mk is input as the file name, and then click Finish ".


Figure 7: add the new NDK build File "Application. mk" to the sample project

Edit the file "Application. mk", add the line "APP_ABI: = all" as follows, and save the file.


Figure 8: edit the Application. mk file to set the "all" architecture as the target

Build an application, verify whether it builds an x86 library, and test the application in the x86 simulator.

When we re-build the application, it will be built for all the supported abi in the ndk. Right-click Eclipse and choose "hello-jni" from the shortcut menu ". Eclipse will automatically call the NDK build and generate all native libraries. You can verify it in the library folder as follows.


Figure 9: Eclipse project resource manager displays the generated native Library

Eclipse will deploy the application in the simulator. At this point, we should see that the application runs successfully, as shown in the screenshot:


Figure 10: the example application is successfully run in the x86 Android simulator.

We hope this article will help you understand how to configure Eclipse ADT to use it in NDK code development, and how to use the NDK build File "Application. mk to build the required target ABI.

Related Articles and resources:

  • Intel hardware accelerator execution Manager (Intel HAXM)
  • Intel Graphics Performance Analyzer 2014 (Intel GPA)

Statement

This document contains information about Intel products. This document does not constitute authorization for any intellectual property rights, including express, implied, or based on the Anti-statement principle or others. Intel is not liable for any other responsibilities. Intel hereby disclaims: this document does not constitute any express or implied warranty of Intel regarding the use and/or sale of its products, including) any liability or warranty for the applicability of a specific purpose, the (ii) merchantability and (iii) Infringement of any patent, copyright or other intellectual property rights.

This document contains information about Intel products. This document does not constitute authorization for any intellectual property rights, including express, implied, or based on the Anti-statement principle or others. Intel is not liable for any other responsibilities. Intel hereby disclaims: this document does not constitute any express or implied warranty of Intel regarding the use and/or sale of its products, including) any liability or warranty for the applicability of a specific purpose, the (ii) merchantability and (iii) Infringement of any patent, copyright or other intellectual property rights.

Intel has the right to change the product specifications and descriptions at any time without notice. The designer shall not trust any feature that is not available to any unique product, nor shall the designer trust any feature marked with a reserved license or undefined license or feature description. In this regard, Intel reserves the right to define it in the future. At the same time, Intel shall not assume any responsibility for conflicts and incompatibility arising from its subsequent changes to such descriptions or feature descriptions. The information provided here can be changed at any time without notice. Do not design a product based on the information provided in this document.

The products described in this document may contain design defects or errors that make them inconsistent with the declared specifications. These defects or errors are included in the error table and can be obtained upon request.

Before placing an order, contact your local intel business department or distributor to obtain the latest product specifications.

To obtain a copy of the document with serial numbers or other intel literature involved in this article, call 1-800-548-4725, or visit: http://www.intel.com/design/literature.htm

The software involved in the Performance Testing Process and its performance can be optimized only in the Intel microprocessor architecture. Tests such as SYSmark and MobileMark are based on specific computer systems, hardware, software, operating systems and functions. Changes to any of the above elements may lead to changes in the test results. Refer to other information and performance tests (including running performance when used in conjunction with other products) to fully evaluate the target product.

The provision of software source code contained in this document is based on the relevant software license and any use and reproduction of such source code shall be subject to the terms of the relevant software license.

The Intel and Intel logos are trademarks of Intel in the United States and/or other countries.

Intel reserves all rights reserved on April 9, 2012. Retain ownership.

* Other names and brands may be assets of other owners.

Statement of Optimization

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.