Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Creating an x86 and ARM* APK using the Intel® Compiler and GNU* gcc

$
0
0

Table of Contents

  1. Introduction
  2. Preparing the Build Environment
  3. Build from Command Line
    1. Configuring the Application
    2. Cleaning the Application Workspace
    3. Building the Binary for ARM* Architecture
    4. Building the Binary for x86 Architecture
    5. Preparing Application package (APK)
  4. Build from Eclipse* IDE
  5. Note on Avoiding Cleanup the Binaries under .\libs\[targetabi]

Introduction

There are Android* devices running on processors supporting ARM* or x86 instruction set architectures (ISA). Different ISAs are not binary compatible and hence an application, if containing native code, should provide native libraries for each targeted ISA. The 'fat' Android* application packages ('fat' APK) is one of the distribution mechanisms for such applications.

This article provides the step by step instructions on building such 'fat' apk that includes the ISA-independent dex files for Dalvik* virtual machine (Dalvik, 2013) as well as the libraries for different ISA targets. It includes building the native application library for x86 using the Intel® C++ Compiler for Android*.

We will use hello-gl2 sample from the NDK r9 distribution for demonstration.

Preparing the Build Environment

The following tools are necessary and should be installed:

Adding the necessary directories to the "PATH" environment variable:

  • Directory "[ndk-dir]" for using "ndk-build" tool
  • Directory "[android-sdk-dir]\sdk\tools" for using "android" tool
  • Directory "[ant-dir]\bin" for using "ant" tool
  • Directory "[jdk6-dir]\jre\bin" for using "java" VM. This is required by "ant" tool
    For Windows environment, make sure to use short-folder name like "PROGRA~2" for "program files (x86)"
  • Creating a new env-var "JAVA_HOME=[jdk6-dir]"

Build from Command Line

This section provides the instructions on how to create the APK package to support Android devices with ARM* and x86 architectures from a command line build environment.

First open a command window or terminal window on Linux*; go to the Android NDK sample "hello-gl2" directory [ndk-dir]\samples\hello-gl2; and follow the steps below.

Note: All the tools noted in above section should be accessible from this window.

  1. Configuring the Application

    Run the following command from the "hello-gl2" directory to generate a build.xml file that will be used to build the sample later.

        $ android update project --target android-18 --name HelloGL2 --path . --subprojects
            --target android-18: corresponds to Jelly Beans MR2 Android release.

  2. Cleaning the Application Workspace

    Use the following command to clean the whole workspace including libraries for all ISA architectures.
        $ ant clean
        $ ndk-build V=1 APP_ABI=all clean
            . V=1 : prints all the commands as they are being executed.
            . APP_ABI=all : forces cleanup of intermediate files for all targets. If this parameter is omitted only the armeabi target will be cleaned.

  3. Building the Binary for ARM* Architecture

    Use the command below to build the application binary for ARM architecture:
        $ ndk-build APP_ABI=armeabi V=1 NDK_TOOLCHAIN=arm-linux-androideabi-4.8
            . APP_ABI=armeabi : configures compilation for the ARM* target.
            . NDK_TOOLCHAIN=arm-linux-androideabi-4.8 : overrides the default GNU* gcc 4.6 and uses gcc 4.8.

    The application binary (libgl2jni.so ) is created at .\libs\armeabi\libgl2jni.so

  4. Building the Binary for x86 Architecture with Intel Compiler

    Use the command below to build the application binary with Intel compiler for x86 architecture:
        $ ndk-build APP_ABI=x86 V=1 NDK_TOOLCHAIN=x86-icc NDK_APP.local.cleaned_binaries=true
            . APP_ABI=x86 : configures compilation for the x86 architecture.
            . NDK_TOOLCHAIN=x86-icc : overrides default compiler gcc 4.6 with Intel C/C++ compiler for Android.
            . NDK_APP.local.cleaned_binaries=true : suppresses the library removal in the libs/armeabi directory. See notes at the bottom.

    The application binary (libgl2jni.so ) is created at .\libs\x86\libgl2jni.so

  5. Preparing Application package (APK)

    After all of the binaries have been built for each Android target, check that the libs\[targetabi] directory contains required library for each targeted architecture.

    To simplify the package creation and avoid package signing, use the following command to create a debug package:
        $ ant debug

    After that the new HelloGL2-debug.zip package can be found in the .\bin directory. It can be run on x86* or ARM* emulators supporting API level 18 or higher provided by Android SDK.
    The HelloGL2-debug.zip package contains libraries for 2 targets: ARM EABI and x86.

Build from Eclipse* IDE

  1. Open Eclipse and load the sample [ndk-dir]/samples/hello-gl2
    • Select menu File > New > Project > Android Project...
    • Select the Android project from existing code button
    • Select any API level above Android 1.5.
    • In the Root Directory field, click Browse... and select the [ndk-dir]/samples/hello-gl2 directory.
    • Click Finish.
  2. Add Native Support to the project:
    Right click on project name and select Android Tools > Add Native Support...
  3. Create a separate build configuration for each target platform and set build command
    Right click on project and select Project properties -> C/C++ Builder -> "Manage configurations..."
    Click New to add following new configurations based on Default configuration:
    • "x86_icc" for x86 target using Intel Compiler icc
    • "amr_gcc" for ARM target using GNU gcc
    Still on the same Project Properties window, set Configuration to "x86_icc":
    • Uncheck "Use default build command"
    • Adding following to Build command field:
      ndk-build APP_ABI=x86 NDK_TOOLCHAIN=x86-icc
    Again on the same Project Properties window, set Configuration to "arm_gcc":
    • Uncheck "Use default build command"
    • Adding following to Build command field:
      ndk-build APP_ABI=armeabi NDK_TOOLCHAIN=arm-linux-androideabi-4.8
    • Click OK
  4. Clean the whole application workspace
    Right click on project and select Build configurations > Clean all…

    Note: if Application.mk exists under jni directory, make sure it does not have following line:
    NDK_APP.local.cleaned_binaries=true

  5. Build the app binary for ARM* target using gcc
    • Create Application.mk under jni directory and add the following line:
      NDK_APP.local.cleaned_binaries=true
    • Right click on project and select Build configurations > Set Active > arm_gcc
    • Right click on project and select Build Project
    • Verify the output binary file at [eclipse-workspace-dir]\GL2JNIActivity\libs\armeabi\libgl2jni.so
  6. Build the app binary for x86 using Intel Compiler
    • Right click on project and select Build configurations > Set Active > x86_icc
    • Right click on project and select Build Project
    • Verify the output binary file at [eclipse-workspace-dir]\GL2JNIActivity\libs\x86\libgl2jni.so
  7. Build all the app binaries for all targets configured
    • Create Application.mk under jni directory and add the following line:
      NDK_APP.local.cleaned_binaries=true
    • Right click on project and select Build configurations > Build All...
    • Verify the output binary files at:
      • [eclipse-workspace-dir]\GL2JNIActivity\libs\armeabi\libgl2jni.so
      • [eclipse-workspace-dir]\GL2JNIActivity\libs\x86\libgl2jni.so
  8. Create unsigned appliation packages
    Right click on project and select Android Tools > Export Unsigned Application Package...

Note on Avoiding Cleanup the Binaries under .\libs\[targetabi]

Use of NDK_APP.local.cleaned_binaries=true parameter to suppress the removal of the previously built libraries may stop working in the future NDK releases. Please consult the [ndk-dir]/build/core/setup-app.mk makefile on how to disable delete actions for the target clean-installed-binaries.

  • Desarrolladores
  • Apple Mac OS X*
  • Linux*
  • Microsoft Windows* (XP, Vista, 7)
  • Android*
  • C/C++
  • Intel® C++ Compiler
  • Dirección URL

  • Viewing all articles
    Browse latest Browse all 1616

    Trending Articles



    <script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>