mupdf include native lib gradle - android

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.

Related

Unable to find mixed_sample.so

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?

Android Studio: Link of external JAR in a multi modules project

I have an Android application (running on Android Studio). It is made of 2 modules:
- There is a low level pure java module (let’s call it module A).
- On top of it, there is the module B which is the Android application. It relies on moduleA for some processings.
This is working fine.
I now need the module A to call an external Library. I have downloaded the JAR file and put it in moduleA/libs folder.
This libs folder is referenced in gradle dependency of moduleA so the compilation is OK. However, there is an exception at runtime:
FATAL EXCEPTION Caused by: java.lang.ClassNotFoundException: Didn't find class "XXXX" on path: DexPathList
I have seen that the APK doesn’t contain the JAR file so it is normal that this exception occurs.
If I copy the same JAR file in moduleB/libs, then it works fine but I have the JAR file two times in the project! What is the clean solution to handle this?
I guess that it can be solved with gradle but I don't know how.
Thank you very much
Olivier
I have been able to fix this issue. This reading about Gradle helped me a lot:
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Creating-a-Library-Project
Here is what I have done:
Instead of putting the JAR file in moduleA/libs folder, I have imported the JAR file in Android Studio by clicking on the project then right click -> new -> module. I then clicked on “Import .JAR/.AAR package”.
This created a module containing the JAR file + a gradle script.
Then, in moduleA’s gradle script, I have added this in the dependencies:
compile project(path: ':name_of_the_jar_file')
I rebuilt all and it works. The JAR file is now present in the APK and there is no more crash at runtime.

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.

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

Categories

Resources