Use the android* x86 NDK for eclipse* and porting the NDK Demo sample application

Source: Internet
Author: User

Goal

The Android plugin for Eclipse (ADT) now supports NDK-based application development.

It can proactively generate project and artifact files, as well as code stubs, and can be integrated into the entire Android application development (building native libraries, copying libraries to the corresponding JNI directory within the project, packaging the app, and generating a finally APK with NDK code). This article will discuss how to configure Eclipse to take advantage of this feature. and demonstrate examples of porting NDK applications.

Configuring the Eclipse ADT plugin to work with the NDK

You must first configure the Eclipse ADT plugin to point to the location of the NDK installation path. To use this new feature. Be sure to update the ADT plugin in Eclipse to get the latest changes and download the latest NDK from the following sites:

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

In Eclipse, open the Preferences->android->ndk form. For example, the following see the input NDK installation path (here we assume you have downloaded the NDK to C:\SW\ANDROID-NDK on Windows *), click Apply, and then click OK.


Figure 1:eclipse NDK configuration in the Android ADT plugin

We should now enable and activate the NDK-related features in Eclipse ADT. Let's open one of the NDK JNI demo samples and build them.

Open the Hello-jni Demo sample NDK app in Eclipse. and add NDK build support to the project

To build an NDK JNI native demo sample in Eclipse, we need to let Eclipse ADT know that the demo sample uses native/NDK code.

Let's first import the Hellojni demo sample into Eclipse.

Open Android project from existing code, new, project, files, file, in Eclipse.

In the next screen, enter the path to the Hello-jni Demo sample project (available in the NDK installation directory). and select the "Copy to Workspace" check box. Then click "Finish".

Use the Hellojni path from your NDK installation directory to replace the root directory path.


Figure 2: Importing the Demo sample Hellojni project into Eclipse

Because the x86 Android NDK supports gingerbread* and a higher Android platform. We want to make sure to update the minimum and target SDK configurations in the application descriptive narrative file. In Eclipse, open the Hellojni Demo sample under Androidmanifest.xml. Click Use SDK in the Androidmanifest editor and check to see if the minimum SDK is set to ten (API 10).


Descriptive narrative file editor in Figure 3:eclipse

We are now ready to join NDK build support for this project in Eclipse.

In Eclipse. Right-click Hello-jni Project (COM.EXAMPLE.HELLOJNI.HELLOJNI), Android tools, ADD Native support, complete.


Figure 4: Adding NDK support to projects in Eclipse

This will update the project configuration with the settings related to the NDK widget.

As we build the project again. It will compile and build the NDK code first and copy the built library to the corresponding project directory. Then continue with the regular APK build process.

Build and execute apps in the simulator

Continue building apps today. and execute it in the Android emulator.

We assume that the gingerbread x86 AVD has been executed on the HAXM-based Android emulator.

In Eclipse, right-click the Hello-jni Project (Com.example.hellojni.HelloJni), execute AS-a Android app. Eclipse should proactively rebuild the project itself and try to deploy/execute the APK on the emulator.

However, when the emulator executes, we see the following error message. This is because the default NDK project settings do not support x86.


Figure 5: Performing a demo sample application in the simulator

In Eclipse, you can see Logcat display error "Unable to load Hello-jni"


Figure 6:logcat shows that the native library could not be loaded

By default, the NDK build does not build itself for the x86 ABI itself. We will need to create the artifact file "Application.mk" to understand the designation of our build target, or to pass the command line parameters to the NDK build command.

Porting apps to use the x86 ABI and NDK build files

We can change the project to support the x86 ABI.

In Eclipse, right-click the JNI directory in the HELLO-JNI project and select New, file, enter APPLICATION.MK as the file name, and then click Finish.


Figure 7: Adding the new NDK build file "Application.mk" to the Demo sample project

Edit the file "Application.mk", such as the following to see the join line "App_abi: = All". Then save the file.


Figure 8: Edit the Application.mk file to target the "all" schema

Build the app to verify that it builds the x86 library. and test the application in the x86 simulator

Currently, when we build the app again, it will be built for all the supported ABI in the NDK. Right-click "Hello-jni" in the Android app, Eclipse---. Eclipse will itself invoke the NDK build itself and generate all the native libraries.

You can verify it in the library directory, for example, as seen below.


Figure 9:eclipse Project Explorer shows the generated native library

Eclipse will deploy the app in the emulator. At this point we should see the app execute successfully, as seen in the screenshot:


Figure 10: Demo sample app successfully executed within the x86 Android emulator

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 desired target ABI.

Related articles and resources:

    • Intel Hardware Acceleration Run Manager (Intel? HAXM)
    • Intel? Graphics Performance Analyzer 2014 (Intel? GPA)

Statement

This document contains information about Intel products. This document does not constitute an authorization for any intellectual property rights, whether express, implied, or based on the principle of estoppel or otherwise.

Intel assumes no liability whatsoever.

Intel hereby disclaims this disclaimer: This document does not constitute any express or implied warranty by Intel as to the use and/or sale of its products, including the applicability of (i) to a particular purpose in respect of its products, (ii) merchantability, and (iii) any patent, The liability for infringement of copyright or other intellectual property rights, regardless of responsibility, or any warranty whatsoever.

This document contains information about Intel products. This document does not constitute an authorization for any intellectual property rights, whether express, implied, or based on the principle of estoppel or otherwise. Intel assumes no liability whatsoever. Intel hereby disclaims this disclaimer: This document does not constitute Intel's warranty of any kind, either express or implied, regarding the use and/or sale of its products. contain no liability whatsoever or warranty whatsoever for the suitability of the product (i) for a particular purpose, (ii) merchantability, and (iii) for any infringement of any patent, copyright or other intellectual property.

Intel reserves the right to change product specifications and descriptive narratives at any time. without prior notice. Designers should not be trusted that no matter what the characteristics of the special products, the designer should not be relied on, no matter what the reserved rights whereas or not defined whereas description or characterization narrative. In this respect, Intel reserves the right to define it in the future. At the same time, Intel shall not assume any responsibility whatsoever for conflicts and incompatibilities arising from the subsequent alteration of such descriptions or descriptive narratives of the features.

The information provided here is subject to change at any time. without prior notice. Do not complete a product design in accordance with the information provided in this document.

The products described in this document may include design flaws or errors that make them inconsistent with the stated specifications.

These defects or errors are included in the errata and can be obtained.

Before placing an order, please contact your local Intel sales office or distributor to obtain the latest product specifications.

For a copy of the numbered document or other Intel literature that is covered by this article, call 1-800-548-4725 or visit: http://www.intel.com/design/literature.htm

The software and its performance involved in the performance testing process are optimized only under the architecture of Intel microprocessors. Tests such as Sysmark and Mobilemark are based on specific computer systems, hardware, software, operating systems, and functions.

Any change in the above factors may lead to changes in test results. Please refer to other information and performance tests (including performance in conjunction with other products) to conduct a comprehensive assessment of the target product.

The provision of the software source code included in this document is made in accordance with the relevant software license. Any use or reproduction of such source code shall be in accordance with the terms of the relevant software license.

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

Intel Corporation? 2012 All rights reserved. All rights reserved.

* Other names and brands may be the property of all other persons.

Optimization statement

Use the android* x86 NDK for eclipse* and porting the NDK Demo sample application

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.