Today, the Android is one of the most famous frameworks to build mobile applications. It has a set o powerfull functionalities to ease the access to several features: from the network interfaces to the graphical libraries.

However, one of the Android’s most curious features is the capacity to extend the standard framework through the implementation of a new set of native functions.  Commonly, this is used in Android when having the requirement for a hardware specific solution and/or application.

The set of posts we’ll introduce at this blog will basically cover the main functionalities of Android NDK (Native Development Kit) as well as the steps to configure the build and development environments. The posts will be divided into three different parts:

  1. Downloading, installing and configuring the build environment;
  2. Building a sample application using NDK, where Java environment calls a set of native functions;
  3. Building a sample application using NDK, where a native lib (written in C++) callbacks the Java environment.
  • Configuring the build and development environment:
First of all, the following softwares and packages must be downloaded:
  1. ADT bundle for your platform from:  http://developer.android.com/sdk/index.html.
  2. Android Native Development Kit (NDK). Again, select the version specific for your platform from: http://developer.android.com/tools/sdk/ndk/index.html.
  3. [Only for Windows users] Get the cygwin environment at: http://cygwin.com/install.html.
Installing and configuring the environment:
        1. Configuring the ADT bundle:
              1.1 –  Uncompress the ADT bundle downloaded file and execute the “eclipse“, application;
              1.2 – Now it is necessary to install CDT eclipse plugin in order to recognize the C/C++ source-code we’ll do. Then, go to the “Help” menu, and select the option: “Install New Software”;
              1.3 –  On “Work with: ” field, put the following server address:  http://download.eclipse.org/tools/cdt/releases/indigo and press <Enter>;
              1.4 –  Wait for a while until the bellow list is filled then check the “CDT Main Features” checkbox and click on “Next” button;
              1.5 – Accept the listed packages and then click on “Next” button.
              1.6 –  Accept the license terms and click on “Finish” button.
              1.7 –  Repeat the process from 1.2) to install the NDK plugin using the following repository:  https://dl-ssl.google.com/android/eclipse/.
              1.8 –  Mark the “NDK Plugins” (as listed by bellow picture) option and repeat the steps previously described.
             1.9 –   After the plugin installation finishes, restart the eclipse IDE.
             1.10 –  Set the path to where NDK is installed. To do it, open ADT preferences menu, go to “Android” option, and then select “NDK“:
       2. Configuring the Native Development Kit (NDK):
            2.1 – Uncompress the NDK installation packet you’ve downloaded from Google website;
            2.2 –  [Only for Windows users]: You must uncompress the NDK folder to a path which do not have a blank space, otherwise, eclipse will not be able to find the path to the NDK.

                   Ex.: (Right) NDK uncompressed to C:\AndroidDev\android-ndk-r8c.

(Wrong) NDK uncompressed to C:\Program Files\android-ndk-r8c.

            2.3 –  [Only for Linux/OSX users]: It is highly recommended to set the $NDK_HOME environment variable. In order to do it:
                  2.3.1 –  Edit your “~/.bash_profile” file (if you don’t have it yet, feel free to create a blank one).
                  2.3.2 –  Export the NDK_HOME variable set its value to the path where android-ndk zip file was uncompressed.
                                   Ex.: Considering that you’ve uncompressed it to the following folder:   /Users/iMobilis/Downloads, you should add the following line to the “~/.bash_profile” file:
[sourcecode language=”bash”] export NDK_HOME=/Users/iMobilis/Downloads/android-ndk-r8c [/sourcecode]

        3.  [Only for Windows users] Configuring Cygwin:
For Windows users, after installing cygwin, in order to properly have the NDK support inside eclipse, it   is necessary to insert the path to cygwin “bin” folder on Windows “Environment Variables”
On the next post we’ll see how to create an Android application which calls the native code.

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

*
*
Website