Unable to access Native .so files in Android Studio - android

I am trying to add armeabi .so files in my Android Studio project. Which will be accessed by .jar files of an SDK. Basically I am using Brothers Printers SDK and integrating them in my app. THe problem is, the .jar files are picked up in the Android Studio Project but when I try to access a method of the SDK, it gives me this error:
java.lang.UnsatisfiedLinkError: Couldn't load createdata from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.wingoku.printerapp-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.wingoku.printerapp-1, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.brother.ptouch.sdk.JNIWrapper.<clinit>(JNIWrapper.java:16)
at com.brother.ptouch.sdk.Printer.setPrinterInfo(Printer.java:887)
at com.wingoku.printerapp.print.printprocess.BasePrint.setPrinterInfo(BasePrint.java:73)
at com.wingoku.printerapp.print.printprocess.BasePrint$PrinterThread.run(BasePrint.java:433)
I have tried putting the armeabi folder inside the src/main/jniLibs but the .so files are not getting picked up and I keep getting the mentioned exception.
What can I do resolve it?

The method which helped me is:
make a directory on your desktop name it 'lib'
take your jnilibs folders with *.so files and paste it in lib.
now zip your lib folder
and then change its extention from .zip to .jar
that is lib.zip to lib.jar
now copy this into your libs folder of your project and update you gradle by adding this line in dependencies:
compile fileTree(include: 'lib.jar',dir:'libs')
this is the safest method to load any jnilibs. i applied it with opencv libs
if also problem persists add reference of NDK-root in your app.
hope this helps.

Related

How I can use the .so File of another project into my own project

I want to use .so lib file of another project into my own project.
There i am facing some problems i have put the .so file in JNILibs folder.
but the native methods in the .so file did not successfully loaded and give error that the Can not find the corresponding JNI Function.
so how i can solve this problem i have checked different solutions like
Call shared library (.so) methods within Android Studios C files
How do I package .so files into my .aar archive?
but they did not solve my problem.
i have no .cpp file nor .h file.
I have only .so file so how i can solve this problem.
thanks in advance.

Secugen sdk not working in xamarin

I am trying to use secugen sdk in which I have binded a jar with project. I have added required jar and .so files to project.I have added required .so files by making a lib folder and inside lib folder making sub folders armeabi and x86.
Inside this sub folders I have placed the .so files.At runtime I'm getting exception as follows:
Java.Lang.UnsatisfiedLinkError:
dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/fingerprint.fingerprint-1/base.apk"],nativeLibraryDirectories=[/data/app/fingerprint.fingerprint-1/lib/arm,
/data/app/fingerprint.fingerprint-1/base.apk!/lib/armeabi-v7a,
/vendor/lib, /system/lib]]] couldn't find "libjnisgfplib.so"

Error when tring to implement SQlcipher in android

java.lang.UnsatisfiedLinkError:
dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/com.example.sqlcipher_demo-1/base.apk"],nativeLibraryDirectories=[/vendor/lib,
/system/lib]]] couldn't find "libsqlcipher_android.so"
I am getting this error. i added all the jar files in libs folder n able to see .so files in all the folders. those jar files are also added in build.gradle file.
source : https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
Finally I got the answer for this....
If you maintain your project structure as mentioned below it will work
Image
For further steps I followed
https://androidbycode.wordpress.com/2015/02/18/android-database-encryption-using-sqlcipher/
and now its working fine.

How to add prebuilt .so library in android studio 0.8.6

The Error I will get is
Couldn't load json from loader dalvik.system.PathClassLoader[DexPathList[dexElements=[zip file "/data/app/com.uei.tools.ndktest-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.uei.tools.ndktest-1, /vendor/lib, /system/lib]]]: findLibrary returned null
I created a zip file of all .so files and i added into libs folder under app folder i added jar dependency from Module settings dependency.
All serch resulted in sample code of old versions of android studio but there is no sample for Android studio 0.8.6 beta
With Android Studio 0.8.x, you can directly add your prebuilt .so files under a jniLibs folder, inside folders corresponding to each ABIs. For example:
app/src/main/jniLibs/armeabi-v7a/libMyLib.so
app/src/main/jniLibs/x86/libMyLib.so
You can find up-to-date samples at the bottom of this page: http://tools.android.com/tech-docs/new-build-system#sites-attachments

Why the manually added .so file in libs is automatically deleted by running the Android project?

I have an Android project A, with ndk and jni features.
It also links to another library project B.
In order to make things simpler, I remove the linked library project B,
and add the compiled .jar file and its .so files in /libs from B.
I put a line
System.loadLibrary("libfromB.so");
Now I clean and rebuild the project A. All is fine.
I find that every time I run the project, libfromB.so in /libs is deleted.
So it will complain:
02-21 17:47:26.493: E/AndroidRuntime(24086): java.lang.UnsatisfiedLinkError: Couldn't load fromB from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.android.askquestion.app-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.android.askquestion.app-1, /vendor/lib, /system/lib]]]: findLibrary returned null
However, I see some Android projects from open source, they have some .so files put in /libs, and they are not deleted automatically.
You should not put your .so files directly under the libs/ directory, but rather under an architecture appropriate subdirectory, for example
project/libs/armeabi/libfromB.so
It is possible that if your IDE believes your project has native code, it might be running an NDK build subsystem which is cleaning that directory.
System.loadLibrary() takes a short library name, not a filename. So if your library is called "libfromB.so" you should use
System.loadLibrary("fromB");

Categories

Resources