Unable to find mixed_sample.so - android

I'm trying to build tutorial-2-mixedprocess application (in android-studio) that came with the opencv-SDK 3.2.0. But my application crashes because of a missing mixed_sample library
// Load native library after(!) OpenCV initialization
System.loadLibrary("opencv_java3"); //This one is taken care in CmakeLists.txt
Log.d(TAG, "Loaded the opencv"); //This line appears on the monitor
System.loadLibrary("mixed_sample"); // C-R-A-S-H h h h
I looked inside OpenCV-android-sdk/sdk/native/libs directory that came with opencv-3.2.0-android-sdk.zip but *mixed_sample.so is nowhere to be found.
Where to find this file?
EDIT
The full error says following:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.opencv.samples.tutorial2-1/base.apk"],nativeLibraryDirectories=[/data/app/org.opencv.samples.tutorial2-1/lib/x86, /vendor/lib, /system/lib]]] couldn't find "libmixed_sample.so"

In Android Studio do the following
Create Folder "jniLibs" inside "src/main/"
Put all your .so libraries inside "src/main/jniLibs" folder
just sync gradle again and project. Run your application.
make sure you have put java and jnilibs at proper places.
can you share tree structure of project screenshot?

Related

Android Library unsatisfied link error with jar file

I have one project that includes a sample app, and a module that we'll call the sdk that I created that I will eventually package up as an .aar file when all is complete. The sample app tells the sdk to run a service. This service requires the use of external libraries that have been packaged as a .jar file that includes .so files. The issue is that every time I try to load the libraries, I get an unsatisfied link error saying that the .so file does not exist and therefore cannot open the library. I'm not quite sure if I'm placing everything in the right place as the error says. If I am missing a step, I was hoping someone could help point me towards the right direction. Below I'll show the file structure of my project as well as what I'm doing to try to open the library.
File Structure
`- MY PROJECT
- My Sample App (com.mine.mysampleapp)
- build
- src...etc
- SDK (separate module) (com.mine.mysamplesdk)
- build
- libs
- my-lib.jar
- assets
- arm64-v8a
- my-lib.so
- armeabi-v7a
- my-lib.so
Library Loading Code
System.load(context.getFilesDir() + "/my-lib.so");
What I'm not understanding is that the .so file lives inside the sdk but the error message:
dlopen failed: library "/data/user/0/com.mine.mysampleapp/files/my-lib.so" not found
shows that it's looking for the file in my sample application.
If you're trying to package as an AAR, those have built in support for JNI libraries: https://www.codepool.biz/build-so-aar-android-studio.html
Rather than putting the libraries in the assets directory and trying to assemble the System.load path yourself, put them in that directory and then you can just System.loadLibrary("my-lib") (note that System.loadLibrary won't actually let you open a library that isn't prefixed with "lib", so you need to rename your library for this to work).

Unable to access Native .so files in Android Studio

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.

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.

mupdf include native lib gradle

I am trying to include mupdf in my Android application.
I run the steps from http://dixitpatel.com/integrating-pdf-in-android-application/
without any problems. But when the app is starting it runs into the following error:
Process: app.main, PID: 9712
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/app.main-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]] couldn't find "libmupdf.so"
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:989)(MuPDFCore.java:14)
The "libmupdf.so" File is placed in the lib folder and I am using Android Studio with gralde.
I hope anyone can help me with that problem.
Put the .so files in lib/armeabi and lib/armeabi-v7a
In the build.gradle add jniLibs.srcDirs = ['libs'] to the existing source sets - see How can I add .so files to an android library project using gradle 0.7+ for more details.

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