Amelia@Amazon avatar image
Amelia@Amazon posted

Using Android Studio for NDK Development


Android Studio is not officially supported for JNI development, and the process to get it working is a bit more complicated and confusing compared to Eclipse.


Some work is required to get JNI projects working properly with Android Studio. The main step that must be taken after importing is to add an "ndk.dir" variable to the file so that gradle can properly compile the project using the NDK example files as follows to illustrate where the variable is set.

Sample Code


This variable should point to the location on the computer where the NDK was extracted. Possible to to include .so libary files directly without having Android Studio doing any of the compilation in addition to being able to compile C and C++ source files using the NDK in Android studio. Also, you will need to add your ndk project into the app's build.gradle file such as the example below.

Sample Code

    android {
        compileSdkVersion 21
        buildToolsVersion "21.1.2"
        defaultConfig {
                applicationId "com.example.hellojni"
                minSdkVersion 3
                targetSdkVersion 3
                ndk {
                    moduleName "hello-jni"
                    stl "stlport_shared"
            testApplicationId "com.example.hellojni.tests"
            testInstrumentationRunner "android.test.InstrumentationTestRunner"
        buildTypes {
                release {
                    minifyEnabled false

However, note that this mechanism has been officially deprecated in Android Studio by Google without having a replacement in place as of yet. For more information about this, please refer to the following Google Code issue: For more information on how to use the currently deprecated NDK compilation within Android Studio, please see:

Keywords: Android Studio, NDK, Eclipse, JNI


10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.



wangchao contributed to this article brizzlebrazzle contributed to this article