Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a .so file in Android Studio

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.

like image 802
Josh Wilson Avatar asked May 23 '13 04:05

Josh Wilson


People also ask

How do I open an .so file on Android?

Actually inside your JNI folder, android NDK which convert your native code like c or c++ into binary compiled code that is called "filename.so". You cannot read the binary code . so it wil create lib folder inside your libs/armeabi/ filename.so file. Show activity on this post.

Where is the .so file in Android?

These files are normally stored in /lib/ or /usr/lib/. On an Android device, SO files are stored within the APK under /lib//.

What is the use of .so file in Android?

The SO file stands for Shared Library. You compile all C++ code into the.SO file when you write it in C or C++. The SO file is a shared object library that may be dynamically loaded during Android runtime. Library files are larger, often ranging from 2MB to 10MB in size.


2 Answers

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

like image 191
Ajay S Avatar answered Oct 11 '22 01:10

Ajay S


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

like image 28
pretty angela Avatar answered Oct 11 '22 00:10

pretty angela