Summary
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.
Resolution
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 local.properties file so that gradle can properly compile the project using the NDK example local.properties files as follows to illustrate where the variable is set.
Sample Code
ndk.dir= sdk.dir=
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: https://code.google.com/p/android/issues/detail?id=82187 For more information on how to use the currently deprecated NDK compilation within Android Studio, please see: http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/
Keywords: Android Studio, NDK, Eclipse, JNI
KB_0001