2015年10月4日 星期日

【Android】Android Studio Support JNI(NDK)

I google ndk + android studio,and  get lots of infomation about how progragming ndk with android studio

Lots of tutorial said that need to put Android.mk and Appliction.mk in jni folder

Now I used Android Stuiod 1.4,and get an excited usage,we don’t need to put above files(Android.mk and Appliction.mk ),just follow below steps ,Android Studio can start programing ndk

1.Download NDK

   First you need to download NDK https://developer.android.com/ndk/downloads/index.html

   (I suppose you’ve installed Android Studio)

2.Define NDK loction

             File => Project Structure => Android NDK location:

             Select where your ndk located

            image

     

       3.Define jni module name

         add below code in defaultConfit of module build.gradle

ndk{
moduleName "leonjni"
}
image 
4.Add jni folder
image 
5.Add load library ,add native method,call native method
image 
6.Generate jni code from native method(alt+enter)
image 
7.Change some text in jni file(c file)
image 
8.Run the app,text in jni file had worked.Have fun.
image