android mupdf libmupdf.so runtime error "No implementation found for native openFile"
Asked Answered
S

3

10

I just finished compiling mupdf from mupdf.com on my mac. Took some time to figure it out but now I have a libmupdf.so in my libs/armeabi folder.

They provide an example of this class called MuPDFCore.java which is viewable here: http://mupdf.com/repos/mupdf/android/src/com/artifex/mupdf/MuPDFCore.java

I used this class in my project and it says the following in LogCat:

Trying to load lib /data/data/com.myapp.android/lib/libmupdf.so 0x4070e050

Added shared lib /data/data/com.myapp.android/lib/libmupdf.so 0x4070e050

No JNI_OnLoad found in /data/data/com.myapp.android/lib/libmupdf.so 0x4070e050, skipping init

No implementation found for native Lcom/myapp/android/viewer/MuPDFCore;.openFile (Ljava/lang/String;)I

DEBUG/AndroidRuntime(27523): Shutting down VM

WARN/dalvikvm(27523): threadid=1: thread exiting with uncaught exception (group=0x400ee760)

ERROR/AndroidRuntime(27523): FATAL EXCEPTION: main

ERROR/AndroidRuntime(27523): java.lang.UnsatisfiedLinkError: openFile

As far as I know the library is loading, before I figured out how to compile the library it kept crashing and saying the "mupdf" is a null link.

Their example pretty much says that openFile is a native function ... Just when I thought I figured this out another problem pops up. Ive been working on it all day. Any input would be great!

Is it a bad compile? I didn't get any errors in the terminal.

Superposition answered 10/3, 2011 at 21:12 Comment(2)
Ah ha! I just figured it out. I looked at mupdf.c and realized there were similarly named functions but they had this long prefix. I realized that the prefix is also a package name. So I put the MUPDFCore back into the com.artifex.mupdf package and it works!Superposition
Please explain your solution, i have been stuck in this problem for a whole day now :(Fustian
W
10

when you try to use it on your project with sample project's so files, it will throw "UnsatisfiedLinkError: Native method not found" exception. The cause is your app package name different from sample app package name("com.artifex.mupdf") because of jni binding system. You can solve this problem with below approaches:

1) long way: change mudef lib source code according to your package name, generate binaries(.so files) from it then use it in your project like @KuoCH said

2) short way: create "com.artifex.mupdf" package in your root source directory(beside project source folder, "src/main/java"), copy all classes from sample project to in it

Wyatt answered 22/4, 2014 at 8:9 Comment(0)
B
5

At file mupdf.c L18-19:

#define JNI_FN(A) Java_com_artifex_mupdfdemo_ ## A 
#define PACKAGENAME "com/artifex/mupdfdemo"

Change both to your package name.

Bondsman answered 17/8, 2013 at 15:52 Comment(0)
S
1

I think you didn't change the your function names in mupdf.c to your corresponding java package name, that means, you should change the function Java_com_artifex_mupdf_MuPDFCore_openFile in your mupdf.c to Java_com_myapp_android_viewer_openFile.

Scamper answered 12/8, 2011 at 5:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.