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.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.company.gimikapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.company.gimikapp-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libtheprebuiltlib.so"
Common solutions I see in SO is this:
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
Tried both
jniLibs.srcDirs = ['C:\\svn\\sys_libs']
and
jniLibs.srcDirs = ['C:/svn/sys_libs']
How do you actually point it to another directory outside your Android project?
This is my CMakeList.txt:
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib
SHARED
src/main/cpp/source/native-lib.cpp )
add_library(theprebuiltlib SHARED IMPORTED)
set_target_properties(theprebuiltlib PROPERTIES IMPORTED_LOCATION
C:/svn/sys_libs/libtheprebuiltlib.so)
target_include_directories(
native-lib PRIVATE
src/main/cpp/source/
C:/svn/sys_includes/)
find_library( log-lib
log)
target_link_libraries( native-lib
theprebuiltlib
${log-lib})
And here is my gradle setup for my JNI:
android {
...
defaultConfig {
...
externalNativeBuild {
cmake {
cppFlags "-frtti -fexceptions"
}
ndk {
abiFilters 'armeabi'
}
}
...
}
...
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
sourceSets {
main {
jniLibs.srcDirs = ['C:/svn/sys_libs']
}
}
}
jniLibs
setting from build.gradle, and check how the APK changes. BTW, maybe the part where you launch cmake is incorrect, please post it here, too. – Alex Cohn