I am trying to include my .so library from another directory. Compiling my project works fine. But when I run it, it gives me
java.lang.UnsatisfiedLi
Apparently, you have NDK r17 installed and Android plugin v.3.1.0 or higher (we don't see this in the published fragment of build.gradle).
But you set abiFilters to armeabi
, which has been dropped. You should set it to armeabi-v7a
, and make sure that libtheprebuiltlib.so
is also built for this ABI, or you can download an older version of NDK and in build.gradle dependencies set
classpath 'com.android.tools.build:gradle:3.0.1'
You can force the latest plugin handle armeabi
if you set it explicitly:
android {
defaultConfig {
ndk {
abiFilters 'armeabi'
}
}
}
(in your script, it is under android.defaultConfig.externalNativeBuild.ndk, so has no effect).
One mistake in your build.gradle, it should read
android {
sourceSets {
main {
jniLibs.srcDir 'C:/svn/sys_libs'
}
}
}
when you have the file C:\svn\sys_libs\armeabi\libtheprebuiltlib.so
. But this does not explain why cmake does not work as expected.
For NDK r16 and Gradle plugin v3.1.2, here is the step by step solution (thanks to @Alex Cohn).
Set android.sourceSets.main.jniLibs.srcDir
to point to the location of external .so
android {
sourceSets {
main {
jniLibs.srcDir 'C:/svn/sys_libs'
}
}
}
Make sure that your external .so is located in the above path (step1), appended by correct architecture. In my case, it is armeabi
, thus my .so is in
C:/svn/sys_libs/armeabi/libtheprebuiltlib.so
Move ndk
from android.defaultConfig.externalNativeBuild.ndk
to android.defaultConfig.ndk
like so
android {
defaultConfig {
ndk {
abiFilters 'armeabi'
}
}
}
Make sure that CMakeLists.txt points to the complete path with proper architecture.
set_target_properties(theprebuiltlib PROPERTIES IMPORTED_LOCATION
C:/svn/sys_libs/armeabi/libtheprebuiltlib.so)