Step by Step - How to create a c++ library with NDK on Android Studio 1.5 (not experimental way)
1. Configure JDK, NDK path environments
I'm using jdk 1.8.0_65 and ndk-bundle. We can use the official ndk also.
2. Add javah, ndk-build as External Tools
(Menu Location is 'Settings > Tools > External Tools')
2-1. Configure javah
2-2. Configure ndk-build
2-3. Configure ndk-build clean
3. Create a new Android Studio Project
4. Add a java class for JNI
5. Create a folder for JNI
6. Configure build.gradle
android {
...
defaultConfig {
...
ndk {
moduleName "your dllname"
}
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "src/main/libs"
}
...
}
...
}
7. First Build
We will encounter an error like 'Error: NDK integration is deprecated in the current plugin. blah blah'.
Because we are not using the experimental class for NDK.
Let's add one line in 'gradle.properties'.
android.useDeprecatedNdk=true
And build again, it must be succeeded.
8. Create a JNI header file
Use 'NDK external tools - javah'
Then we will have a JNI header file.
9. Create a C++ source file
We don't need to check "Create associated header".
10. Create some MakeFiles
Android.mk
Application.mk
11. Build Our NDK Library
12. Let's Use Our NDK Library Function
13. Final Build and Create APK
After build, We must have our library in the APK.
14. Let's Enjoy NDK :)
Written on December 3, 2015