Android: Couldn't load mupdf - android

I am having an (Android Studio - Gradle) Cordova (3.6.4) project.
In my app there can be a list of pdf files which should be shown with mupdf.
But I always get the following error message:
06-10 15:04:38.365 5940-5940/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: de.dil.DSM, PID: 5940
java.lang.UnsatisfiedLinkError: Couldn't load mupdf from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/de.dil.DSM-2.apk"],nativeLibraryDirectories=[/data/app-lib/de.dil.DSM-2, /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.artifex.mupdfdemo.MuPDFCore.<clinit>(MuPDFCore.java:14)
at de.dil.DSM.DSM.loadFile(DSM.java:216)
at de.dil.DSM.xviewer$6.run(xviewer.java:102)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
The java files from mupdf seems to be correctly imported.
It seems to be, that it is "just" the "libmupdf.so" which isn't correctly imported.
The libmupdf.so files are in the following directories:
libs/armeabi/libmupdf.so
libs/armeabi-v7a/libmupdf.so
There is also a c mupdf file here: jni/mupdf.c
Is there anything which I especially need to configure in the settings.gradle or in the build.gradle?
Thanks ahead!!!!

Put your .so files in a jniLibs folder
>src
>main
>jniLibs
>armeabi
|libmupdf.so
>armeabi-v7a
|libmupdf.so

The solution was to add this:
jniLibs.srcDirs = ['libs']
To the existing sourceSets in the build.gradle!

Related

Failed to load .so in android studio

I wanted to load a .so file: System.loadLibrary("example");
but i faced with this error!!
this is the error:
FATAL EXCEPTION: main
Process: com.name.ex, PID: 30737
java.lang.UnsatisfiedLinkError: dlopen failed: file offset for the library "/data/app/com.name.ex-1/lib/arm/example.so" >= file size: 0 >= 0
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.name.ex.example<clinit>(example.java:582)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newApplication(Instrumentation.java:1020)
at android.app.Instrumentation.newApplication(Instrumentation.java:1005)
at android.app.LoadedApk.makeApplication(LoadedApk.java:670)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6395)
at android.app.ActivityThread.access$1800(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
you might have placed the native assembly for ARM into the wrong directory ...or the file-size is indeed 0. it's ordinary called armeabi-v7a instead of arm, for example (the jniLibs path might need to be adjusted, depending how your project looks alike):
app/src/main/jniLibs/armeabi-v7a
in the module-level build.gradle one can define the location:
android {
...
sourceSets {
main {
jniLibs.srcDir "src/main/jniLibs"
}
}
}

UnsatisfiedLinkError - com.datumdroid.android.ocr.simple couldn't find "libjpgt.so"

I'm new to Android Studios and I am doing this OCR http://swlock.blogspot.com/2016/07/ocr-tesseract-2.html where the image convert to text but everytime I take an image app the will close and got this error. Anyone can guide me to fix this error? Thanks
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.datumdroid.android.ocr.simple, PID: 2425
java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_0-classes.dex"],nativeLibraryDirectories=[/data/app/com.datumdroid.android.ocr.simple-2/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libjpgt.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1530)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)
at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:214)
at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onActivityResult(SimpleAndroidOCRActivity.java:138)
at android.app.Activity.dispatchActivityResult(Activity.java:6915)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.
That means that the *.so files are not in your *.apk file. Follow the steps in this stackoverflow question/answer.
You can always go to Build > Analyze APK... to see if the *.so files are getting added. Obviously, if they are not in the APK, then there is no reason to attempt to run the app that needs the *.so files.

cocos2dx Android Studio crash in System.loadLibrary(libName)

I want to use cocos2dx Android Studio in mac.
I downloaded:
android-ndk-r9d, android studio 2.1.1 and apache-ant-1.9.7. cocos2dx 3.11.1
Now I am successfully creating a project by using command:
cocos new TEST -p com.your_company.test -l cpp -d /Users/mac-corei5-1/Desktop/Sayem/cocos2dx/Project
Now when I am trying to run project in Android Studio in emulator or android device it is crashing in System.loadLibrary(libName); where libName=MyGame
I got this crash log in logcat
06-30 04:46:15.291 4866-4866/com.your_company.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.your_company.test, PID: 4866
java.lang.UnsatisfiedLinkError: Couldn't load MyGame from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.your_company.test-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.your_company.test-2, /vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at org.cocos2dx.lib.Cocos2dxActivity.onLoadNativeLibraries(Cocos2dxActivity.java:246)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:260)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Even thought Cocos2d-x 3.10+ has bought in android studio support and gradle build support it still very much buggy. The reasom your build crashes is because you haven't actually created the .so file by using the Android-Studio build option. Try running
cocos compile -p android --android-studio
Via a CLI so that it correctly generates the files.
Then you can run the project via Android-studio, but remember any time you change the source of your game you have to run the CLI command. Proper workaround yet to be found.

Keep .so files from being trimmed when use Proguard in Android

I am using Proguard in my android app to reduce the number of methods (see this). For that I have coded some lines in proguard-project.txt file. All the jars work well after the necessary commands. But when I try to integrate Video Chat part of Quickblox, they provide us a .so that I would have to integrate. So I just keep it in the libs\armeabi\libilbc-codec.so path as guided by them. Now the project runs well when I run it without Proguard, but when I compile it with Proguard, it gives me with following error:
11-21 18:18:19.171: E/AndroidRuntime(19825): FATAL EXCEPTION: Thread-34829
11-21 18:18:19.171: E/AndroidRuntime(19825): java.lang.ExceptionInInitializerError
11-21 18:18:19.171: E/AndroidRuntime(19825): at com.quickblox.videochat.core.objects.AudioRecorder$AudioRecorderRunnable.run(AudioRecorder.java:196)
11-21 18:18:19.171: E/AndroidRuntime(19825): at java.lang.Thread.run(Thread.java:864)
11-21 18:18:19.171: E/AndroidRuntime(19825): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load ilbc-codec: findLibrary returned null
11-21 18:18:19.171: E/AndroidRuntime(19825): at java.lang.Runtime.loadLibrary(Runtime.java:365)
11-21 18:18:19.171: E/AndroidRuntime(19825): at java.lang.System.loadLibrary(System.java:535)
11-21 18:18:19.171: E/AndroidRuntime(19825): at com.googlecode.androidilbc.Codec.<init>(Codec.java:16)
11-21 18:18:19.171: E/AndroidRuntime(19825): at com.googlecode.androidilbc.Codec.<clinit>(Codec.java:5)
11-21 18:18:19.171: E/AndroidRuntime(19825): ... 2 more
11-21 18:18:19.281: E/copybit(19825): Error opening frame buffer errno=13 (Permission denied)
I am very noob to using Proguard as well as NDK, so can anyone guide me as how can I overcome this issue? I have added Native support by Right clicking on project -> Android Tool -> Add Native Support.. and selected the .so file I have been using. So can anyone suggest any solution or the lines that I would have to write to this .so file to work ?
Thanks in Advance.
EDIT:
After following #ph0b's comment, I tried following steps:
I have removed BDK supprot from the app following this tutorial and also unzipped the apk as per his steps and I am getting my "libilbc-codec.so" library under "/lib/armeabi". But still getting the below error. So what might be wrong now ??
11-24 12:12:29.045: E/AndroidRuntime(6049): FATAL EXCEPTION: Thread-455
11-24 12:12:29.045: E/AndroidRuntime(6049): Process: com.hypersquare, PID: 6049
11-24 12:12:29.045: E/AndroidRuntime(6049): java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.google.android.maps.jar", zip file "/data/app/com.hypersquare-1/base.apk"],nativeLibraryDirectories=[/data/app/com.hypersquare-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libilbc-codec.so"
11-24 12:12:29.045: E/AndroidRuntime(6049): at java.lang.Runtime.loadLibrary(Runtime.java:366)
11-24 12:12:29.045: E/AndroidRuntime(6049): at java.lang.System.loadLibrary(System.java:989)
11-24 12:12:29.045: E/AndroidRuntime(6049): at com.googlecode.androidilbc.Codec.<init>(Codec.java:16)
11-24 12:12:29.045: E/AndroidRuntime(6049): at com.googlecode.androidilbc.Codec.<clinit>(Codec.java:5)
11-24 12:12:29.045: E/AndroidRuntime(6049): at com.quickblox.videochat.core.objects.AudioRecorder$AudioRecorderRunnable.run(AudioRecorder.java:196)
11-24 12:12:29.045: E/AndroidRuntime(6049): at java.lang.Thread.run(Thread.java:818)
Proguard shouldn't remove .so files, I guess your issue comes from something else.
When you use "add native support" from eclipse, eclipse creates an empty ndk library project (a jni folder with empty sources and a sample Makefile).
So when you build your app, eclipse empties libs/*/ folders, then build and install the newly created library here.
If you don't use the NDK yourself (not compiling any sources with it), you should remove the jni folder and its content from your project, and put the .so files you need to be packaged into your apk, directly inside libs/(armeabi|x86|...) folders (btw, it's jniLibs instead of libs when using Android Studio).
In order to check what .so files are getting packaged into your app, you can open your APK as a zip file and look under the lib/(armeabi|x86|...) folders.

Sinch Android Messaging Tutorial App crashes upon login and client isn't started

The android tutorial app keeps crashing once a user has been logged in. Client also doesn't start.
Logcat Says
08-03 12:45:16.183 1322-1322/com.example.messagingtutorialskeleton W/linker﹕ libhoudini.so has
text relocations. This is wasting memory and is a security risk. Please fix.
08-03 12:45:16.655 1322-1322/com.example.messagingtutorialskeleton A/libc﹕ Fatal signal 11
(SIGSEGV) at 0x000000b4 (code=1), thread 1322 (utorialskeleton)
This occurs when using a Genymotion emulator.
When using the standard android virtual device, the logcat reads:
08-03 08:45:00.705 2406-2406/com.example.messagingtutorialskeleton E/AndroidRuntime﹕ FATAL
EXCEPTION: main
Process: com.example.messagingtutorialskeleton, PID: 2406
java.lang.UnsatisfiedLinkError: Couldn't load sinch-android-rtc from loader
dalvik.system.PathClassLoader[DexPathList[[zip file
"/data/app/com.example.messagingtutorialskeleton-2.apk"],nativeLibraryDirectories=[/data/app-
lib/com.example.messagingtutorialskeleton-2, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.sinch.android.rtc.internal.natives.jni.UserAgentFactory.<clinit>
(UserAgentFactory.java:9)
at
com.sinch.android.rtc.internal.client.ServiceFactory.createUserAgent(ServiceFactory.java:43)
at com.sinch.android.rtc.internal.client.DefaultSinchClient.<init>
(DefaultSinchClient.java:144)
at
com.sinch.android.rtc.internal.client.InternalSinchClientFactory.createSinchClient(InternalSinchClie ntFactory.java:13)
at
com.sinch.android.rtc.DefaultSinchClientBuilder.build(DefaultSinchClientBuilder.java:95)
at
com.sinch.messagingtutorialskeleton.MessageService.startSinchClient(MessageService.java:58)
at
com.sinch.messagingtutorialskeleton.MessageService.onStartCommand(MessageService.java:42)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2702)
at android.app.ActivityThread.access$2100(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1293)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Whats the problem? Thanks.
Yup i got the fix!...you just need to store all your Sinch architecture files into jniLibs folder as indicated in the tutorial.
The folder hence will include three folders which come along with the SDK namely;
1. Armeabi
2 Armeabi-v7a
3. X86
The error that you're getting is due to the missing x86 folder. Hence Do the needful and if you get stuck then please ask! 😊
The Sinch SDK isn't tested on the Genymotion emulator because it doesn't yet support x86. Here is a full explanation: https://github.com/sinch/android-messaging-tutorial/issues/1#issuecomment-50063315
Have you tried testing the app on a physical device?

Categories

Resources