Android NDK

What is Android NDK

The Android NDK (Native Development Kit) is a companion toolset to the Android SDK that lets you implement parts of your app using native-compiled languages such as C or C++ instead of Java.

Those native parts are structured as a library that you call from your Java code. The compiled native library gets embedded within your application’s .apk file. A separate native library is included for each cpu architecture you target. Most or all of your native source code will be target independent. The whole app runs inside a Java virtual machine on the Android device. The fundamental Android application model does not change.

The NDK works with the basic stand-alone “SDK Tools”, and also with the Android Studio IDE or with the older Eclipse ADT IDE.

The NDK is not designed for use on its own.

For general NDK information common to all cpu targets, see Google’s top Android NDK page .

Installing the MIPS Android NDK

The following instructions assume that you are already familiar with using the SDK Tools and NDK and IDEs to build and run native ARM apps.

The Android NDK can be installed as its own separate download from Google or Android Studio will download it for you at your first use. It is a big download.

The NDK includes native-language cross-compilers for all Android cpu architectures, including MIPS and MIPS64. There are no MIPS-specific steps to take when installing the NDK itself.

Before using the NDK, you must also install some version of the Android SDK toolsets:



Android Studio v1.3 has preliminary support for NDK, but it is incompletely documented and the details are likely to change. Android Studio automatically invokes the NDK compilers for you. You can control which cpu architectures to target via the ndk.abifilters variable in the app/build.gradle script. If you do not set ndk.abifilters, Studio will compile to all available Android cpu architectures. For an example to copy, see the sample NDK program hello-jni. Studio comes with its own revised copies of the NDK sample programs. Studio ignores the app’s jni/ file.

If you instead build your app via the Eclipse ADT or by direct stand-alone SDK Tools commands, you must build or rebuild the native parts of the app first via an ndk-build command line, before
building the Java parts and whole .apk by SDK or ADT steps. ndk-build does not use the app/build.gradle file. The APP_ABI setting in your jni/ config file tells ndk-build which cpu architectures to target. You can select all possible abi targets, or select specific ones to reduce users’ download size and download time. (If there is no file, ndk-build defaults to just one target, the least version of the Arm architecture.)

You can split the targets among several .apk files for minimum size. Google’s Play Store will then send the appropriate file to matching Android devices.

You can test your app on real Android devices or on the SDK’s emulated virtual devices (AVDs). To test a native MIPS app via emulation, you will need to download a MIPS or MIPS64 Android system image for a particular Android release, and then set up a MIPS or MIPS64 AVD with that image. The SDK Tools already includes instruction-set emulators for all Android device architectures. But the Android system images needed for MIPS virtual devices are not downloaded until you ask for them. To get them, open the SDK Manager (package installer) and follow the system image selection steps at mips/android/sdk. Then use the AVD Manager to configure a virtual device running MIPS or MIPS64 instructions.

Then start that AVD and let it fully boot. Then run your test program on that running emulator.