28

I am trying to add an external library, Scandit. I keep getting this error:

    java.lang.UnsatisfiedLinkError: Couldn't load scanditsdk-android-3.3.1 from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.clover.barcode2-1.apk,libraryPath=/data/app-lib/com.clover.barcode2-1]: findLibrary returned null
    at java.lang.Runtime.loadLibrary(Runtime.java:365)
   .....

I assume it is because I am not properly including the .so file that comes with the library, but I can't figure out how to do it.

I am using Android Studio and I added the library by going to module settings -> libraries and added the directory with the jar and the directory with the so file.

hoss
  • 2,430
  • 1
  • 27
  • 42
Josh Wilson
  • 3,585
  • 7
  • 32
  • 53

5 Answers5

79

You can add pre built *.so files in Android Studio using gradle 0.7.2+. First create the jniLibs at this location /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs.

enter image description here

Ajay S
  • 48,003
  • 27
  • 91
  • 111
9

To use native-library (so files) You need to add some codes in the "build.gradle" file.

This code is for cleaing "armeabi" directory and copying 'so' files into "armeabi" while 'clean project'.

task copyJniLibs(type: Copy) {
    from 'libs/armeabi'
    into 'src/main/jniLibs/armeabi'
}
tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn(copyJniLibs)
}
clean.dependsOn 'cleanCopyJniLibs'

I've been referred from the below. https://gist.github.com/pocmo/6461138

pretty angela
  • 2,241
  • 1
  • 19
  • 8
6

I had a libs folder in my project where i included external libraries added the line compile fileTree(dir: 'libs', include: '*.jar') into dependencies {} in the gradle's build file.

Then I made a lib folder and inside it an armeabi folder where I've inserted all the needed .so files. I then zipped the folder into a .zip (the structure inside the zip file is now lib/armeabi/*.so) I renamed the .zip file into armeabi.jar and added it to the libs folder as an external library.

stackanswer
  • 61
  • 1
  • 1
1

I think it's a problem of the new gradle build system. Try the solution of this answer. There is also a link to a google group discussion, that describes solution and the problems more detailed.

Community
  • 1
  • 1
rivare
  • 817
  • 8
  • 6
-1
splits {
    abi {
        enable true
        reset()
        include 'x86', 'x86_64', 'arm64-v8a', 'armeabi-v7a', 'armeabi'
        universalApk false
    }
}

I get this code from facebook fresco library

xiaoyuan hu
  • 175
  • 2
  • 2
  • 2
    Isnt this code for splitting the apk into smaller parts as per dependent systems so that overall apk size gets reduced? – Jalpesh Jan 25 '17 at 07:17