6

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" } } } 

My project architecture

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

10
  • To which library you are getting this error and which architecture your getting this error, this information helps to answer. Commented Feb 8, 2018 at 6:02
  • I have edited my question, I had added the image. I am trying to add the .so file in armeabi and armeabi-v7a. Commented Feb 8, 2018 at 6:12
  • If you are copying manually then it is not right, the library binary file for each architecture is different. Commented Feb 8, 2018 at 6:27
  • Please upload the whole UnsatisfiedLinkError: dlopen failed log. There are many info in the end message indicated what happened actually. Commented Feb 8, 2018 at 6:29
  • sorry, I didn't get you, can you please explain a bit. Commented Feb 8, 2018 at 6:30

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

6 Comments

I have tried by adding this, still same error facing.
@KhyatiChitroda Notice that this is jniLibs.srcDirs, nor jni.srcDirs. Have you unzip your apk to see whether there are so files in /lib?
@KhyatiChitroda It may be in a wrong path because sourceSet starts on module folder... Answer updated.
Thank you so much for your suggestion.
You could accept the answer and vote up if it solves your problem really. :)
|
-1

Or make your main library a SHARED library.

add_library(libname SHARED //files.cpp ) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.