Adding a .so file in Android Studio
Asked Answered
P

5

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.

Perineurium answered 23/5, 2013 at 4:59 Comment(3)
how do you add the .so and put it to what directory?Omar
I just added the directory it is in because I don't know how to add it. They are both located in /libsPerineurium
add a .so file from directory outside android project: #50714433Concatenate
W
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

Washerwoman answered 16/3, 2014 at 18:16 Comment(9)
You saved my life bro, I'm trying to 2½ hours, worked perfectly, all the strange errors are gone, thank you for sharing your wisdom. @Josh Wilson You can mark as a solution?Ichabod
@TGMCians can you please show us gradle piece of code which require for compile .so files.Disinfectant
Thaaaaaaaaaaaaaaanks you helped a lot.Containment
can you please guide me to add lib that is written in C in my android project.Beattie
What is Core class? Can't find itMatchlock
Is there any doc for the place to put so files?Obsession
@TGMCians You are great.. :)Disinfectant
Is prebuilt .hpp file required for cmake. Its urgent please give me replyHectocotylus
Highly appreciate that answer. Thank you. However, is it normal that people like me, coming from a C++ world, struggles so much at finding this answer ? There's almost no documentation that I could find on the native development for Android website. Is it poor documentation or am I just ignorant ?Zodiac
B
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

Bradbradan answered 4/3, 2015 at 7:54 Comment(1)
dont forget to add armeabi-v7 and x86!Introgression
P
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.

Purpleness answered 9/5, 2015 at 1:55 Comment(0)
I
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.

Ignaciaignacio answered 24/6, 2013 at 17:42 Comment(0)
C
-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

Cupbearer answered 7/7, 2015 at 12:16 Comment(1)
Isnt this code for splitting the apk into smaller parts as per dependent systems so that overall apk size gets reduced?Johan

© 2022 - 2024 — McMap. All rights reserved.