Issue
I am facing the issue while I am adding the .so file in my project, from the other ans, I have tried with different solutions but not any solution help me out.
case: 1 I had tried to put my .so in src/main/jniLibs and in the gradle file I had added below lines, but getting the same error.
android {
sourceSets.main.jni.srcDirs = []
}
case:2 I had added cpp folder with native-lib.cpp and in gradle added below code:
defaultConfig {
ndk {
abiFilters "armeabi", "armeabi-v7a", "x86", "mips"
}
}
case:3 I had created new fresh project with c/c++ support and add a .so file under cpp folder and in the gradle added below code:
defaultConfig {
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
}
}
}
error code:
FATAL EXCEPTION: main
Process: ai.kitt.snowboy.demo, PID: 15175
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ai.kitt.snowboy.demo-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libsnowboy-detect-android.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:988)
at ai.kitt.snowboy.audio.RecordingThread.<clinit>(RecordingThread.java:20)
at ai.kitt.snowboy.Demo.onCreate(Demo.java:49)
at android.app.Activity.performCreate(Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.access$800(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1317)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
I am using android studio 3.0.1, gradle: 3.0.1
Solution
Try add this in build.gradle
:
sourceSets.main.jniLibs.srcDirs = ['src/main/jniLibs']
or add following into android
block:
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
Gradle may have problem when read default jniLibs path, just make it implicit.
sourceSets.main.jni.srcDirs
not work because it defines jni source
, like cpp source files folder.
Exception stacks nativeLibraryDirectories=[/vendor/lib, /system/lib]]] shows that system didn't detect your lib at all. To verify it, exact your apk to see whether there is a /lib
folder and your *.so
.
Answered By - sakiM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.