How Do I Use Jni With Aar Library?
I am creating an Android library (.aar file) and I need to use JNI. (I am very well aware of Google's discouragement of using JNI/NDK if possible, but in this case, it's not possib
Solution 1:
Turns out I had to add some NDK config in my build.gradle file inside my AAR module directory.
build.gradle:
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"// This determines the .so filename
ndk {
moduleName "hello-jni"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Not having that added in build.gradle will produce an .so file that's defaulted to your project's name, in my case "libsample-aar.so". With that config above, the generated .so file will then be "libhello-jni.so".
Solution 2:
You must build the native code with the command ndk-build from Android NDK.
This proccess will generate the linhello-jni.so that will be included in your build.
Post a Comment for "How Do I Use Jni With Aar Library?"