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

Building Android* Applications from Command Line

$
0
0

This topic applies to C/C++ on Linux* and Windows* host systems.

You can build applications for x86-based Android* devices in two ways:

  • Using the Intel® C++ Compiler toolchain as a standalone compiler

  • Enabling the Intel toolchain within the Android NDK build system

To do this, install the Android* NDK from http://developer.android.com/sdk/ndk/index.html or the Android* Open Source Project (AOSP) from http://source.android.com/. Refer to the Release Notes for supported NDK versions.

When you install the Intel® C++ Compiler (ICC), the installation program integrates the compiler into the Android NDK build system automatically. icc is the default compiler for Intel architecture-based targets for NDK revisions 9, 9b, 9c and 9d.

Using Intel® C++ Compiler Toolchain as Standalone Compiler

The Intel C++ Compiler requires a GNU compiler toolchain for the Android OS to work.

Perform the following steps on Linux* host systems:

  1. Open a terminal window.

    1. Set up the environment for the Intel Compiler with the following command:

      $ source [icc-install-dir]/bin/compilervars.sh

      where [icc-install-dir] is:

      /opt/intel/system_studio_2015.0.nnn/

Perform the following steps on a Windows* host system:

  1. Open the setup environment window, on Windows* 8.x, from Start Menu > Programs > Intel® System Studio > Command Prompt > IA-32.

    Or

    Open a command window to setup the environment manually.

  2. Set up the environment for the Intel Compiler with the following command:

    >>[icc-install-dir]\bin\compilervars.bat

    where [icc-install-dir] is a directory where compiler installs.

    By default, it is C:\Intel\system_studio_2015.0.nnn/, where nnn is the package build number.

If you see errors requesting to set up ANDROID_SYSROOT and ANDROID_GNU_X86_TOOLCHAIN environment variables, the possible reason is that you used an unsupported NDK version during installation. In such a case, you can set up the environment variables manually.

Using the NDK environment:

If you installed the 32-bit version of the Android NDK, set the environment variables as follows:

//On Linux* system
$ export NDK_DIR=[Android NDK-install-directory]
$ export ANDROID_SYSROOT=$NDK_DIR/platforms/android-18/arch-x86
$ export ANDROID_GNU_X86_TOOLCHAIN=$NDK_DIR/toolchains/x86-4.6/prebuilt/linux-x86
//On Windows* system>>set NDK_DIR=[Android NDK-install-directory]>>set ANDROID_SYSROOT=%NDK_DIR%\platforms\android-18\arch-x86>>set ANDROID_GNU_X86_TOOLCHAIN=%NDK_DIR%\toolchains\x86-4.6\prebuilt\windows-x86

If you installed the 64-bit host version of the Android NDK, set the environment variables as follows :

//On Linux* system
$ export NDK_DIR=[Android NDK-install-directory]
$ export ANDROID_SYSROOT=$NDK_DIR/platforms/android-18/arch-x86
$ export ANDROID_GNU_X86_TOOLCHAIN=$NDK_DIR/toolchains/x86-4.6/prebuilt/linux-x86_64
//On Windows* system>>set NDK_DIR=[Android NDK-install-directory]>>set ANDROID_SYSROOT=%NDK_DIR%\platforms\android-18\arch-x86>>set ANDROID_GNU_X86_TOOLCHAIN=%NDK_DIR%\toolchains\x86-4.6\prebuilt\windows-x86_64

Using the AOSP environment:

If you are using the AOSP environment on a Linux* host, set the variables as follows:

export TOPDIR= #set to the AOSP root directory (example: /export/JB_WW36)
export ANDROID_SYSROOT=$TOPDIR/prebuilts/ndk/8/platforms/android-17/arch-x86
export ANDROID_GNU_X86_TOOLCHAIN=$TOPDIR/prebuilts/gcc/linux-x86/x86/i686-linux-android-4.6

You are now ready to use icc from a command line in the build environment to compile C source code and icpc to compile C++ source code.

Here is an example on Linux* host:

$ cd $NDK_DIR/samples/hello-jni/jni
$ icc -platform=android -c hello-jni.c
$ icc -platform=android –shared -o libhello-jni.so hello-jni.o

Enabling Intel Toolchain within Android NDK Build System

To understand how to enable the Intel toolchain within the Android* NDK build system, follow the steps to build the hello-jni sample application that ships with the Android NDK. You can locate the sample in $NDK_DIR/samples/hello-jni/jni/.

Build the sample application with the Intel® C++ Compiler either from the command line or using the *.mk file. In either approach, you need to configure APP_ABI if you want to use ICC. If multiple versions of the Intel compiler are installed, a full compiler package version can be specified. For example:

NDK_TOOLCHAIN=x86-icc15.x.y.nnn
where x is the minor version, y is the update number, and nnn is the package build number.

From the command line

  1. Open the terminal window and navigate to the jni folder of the sample:

    cd $NDK/samples/hello-jni

  2. Enter the following command:

    $ $NDK_DIR/ndk-build V=1 -B APP_ABI=x86 NDK_TOOLCHAIN:=x86-icc  // 32-bit Linux host
    $ $NDK_DIR/ndk-build V=1 -B APP_ABI=x86_64 NDK_TOOLCHAIN:=x86_64-icc  // 64-bit Linux host
    >>%NDK_DIR%\ndk-build V=1 -B APP_ABI=x86 NDK_TOOLCHAIN:=x86-icc // 32-bit Windows host
    >>%NDK_DIR%\ndk-build V=1 -B APP_ABI=x86_64 NDK_TOOLCHAIN:=x86_64-icc // 64-bit Windows host

    where:

    V=1 enables verbose output (optional)

    -B means rebuild all (optional)

    APP_ABI indicates target architecture.

Using the Application.mk file

  1. Open or create the Application.mk file in your application’s jni folder at $NDK_DIR/samples/hello-jni/jni/.

  2. Add the following lines in Application.mk:

    • For 32-bit targets:

      APP_ABI:=x86
      NDK_TOOLCHAIN:=x86-icc
    • For 64-bit targets:

      APP_ABI:=x86_64
      NDK_TOOLCHAIN:=x86_64-icc
  3. Run the command to build the application:

    $ $NDK_DIR/ndk-build V=1 –B    // on Linux* host
    
    >>%NDK_DIR%\ndk-build V=1 –B   // on Windows* host
    

Inglés

Viewing all articles
Browse latest Browse all 1616

Trending Articles



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