Bug 695381

Summary: Getting an UnsatisfiedLinkError
Product: MuPDF Reporter: Sam <sambrook2000>
Component: appsAssignee: MuPDF bugs <mupdf-bugs>
Status: RESOLVED DUPLICATE    
Severity: major CC: avinasz.n, di.em.ex, jitesh.h.lalwani, matt, nickuem, robin.watts, tor.andersson
Priority: P4    
Version: 1.5   
Hardware: Android Phone   
OS: Android   
Customer: Word Size: ---

Description Sam 2014-07-24 02:14:15 UTC
Hello,

I am using eclipse for developing android application. I am getting the FATAL Error when I am running the MuPDF application. Below is the error:

D/dalvikvm( 1105): Trying to load lib /data/app-lib/com.artifex.mupdfdemo-1/libmupdf.so 0xb2d39818
E/dalvikvm( 1105): dlopen("/data/app-lib/com.artifex.mupdfdemo-1/libmupdf.so") failed: dlopen failed: cannot locate symbol "strtof" referenced by "libmupdf.so"...
W/dalvikvm( 1105): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/artifex/mupdfdemo/MuPDFCore;
D/AndroidRuntime( 1105): Shutting down VM
W/dalvikvm( 1105): threadid=1: thread exiting with uncaught exception (group=0xb2a8aba8)
E/AndroidRuntime( 1105): FATAL EXCEPTION: main
E/AndroidRuntime( 1105): Process: com.artifex.mupdfdemo, PID: 1105
E/AndroidRuntime( 1105): java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "strtof" referenced by "libmupdf.so"...
E/AndroidRuntime( 1105): 	at java.lang.Runtime.loadLibrary(Runtime.java:364)
E/AndroidRuntime( 1105): 	at java.lang.System.loadLibrary(System.java:526)
E/AndroidRuntime( 1105): 	at com.artifex.mupdfdemo.MuPDFCore.<clinit>(MuPDFCore.java:14)
E/AndroidRuntime( 1105): 	at com.artifex.mupdfdemo.MuPDFActivity.openFile(MuPDFActivity.java:214)
E/AndroidRuntime( 1105): 	at com.artifex.mupdfdemo.MuPDFActivity.onCreate(MuPDFActivity.java:320)
E/AndroidRuntime( 1105): 	at android.app.Activity.performCreate(Activity.java:5231)
E/AndroidRuntime( 1105): 	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
E/AndroidRuntime( 1105): 	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
E/AndroidRuntime( 1105): 	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
E/AndroidRuntime( 1105): 	at android.app.ActivityThread.access$800(ActivityThread.java:135)
E/AndroidRuntime( 1105): 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
E/AndroidRuntime( 1105): 	at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 1105): 	at android.os.Looper.loop(Looper.java:136)
E/AndroidRuntime( 1105): 	at android.app.ActivityThread.main(ActivityThread.java:5017)
E/AndroidRuntime( 1105): 	at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1105): 	at java.lang.reflect.Method.invoke(Method.java:515)
E/AndroidRuntime( 1105): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
E/AndroidRuntime( 1105): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
E/AndroidRuntime( 1105): 	at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  382):   Force finishing activity com.artifex.mupdfdemo/.MuPDFActivity
W/ActivityManager(  382):   Force finishing activity com.artifex.mupdfdemo/.ChoosePDFActivity
D/dalvikvm(  382): GC_FOR_ALLOC freed 476K, 22% free 5765K/7356K, paused 56ms, total 61ms




Can you tell me where its going wrong
Comment 1 Robin Watts 2014-07-25 06:24:21 UTC
What version of the ndk are you using? Supposedly versions < 5 declared, but did not define strtof. I'd advise you to build with a newer version. The ndk is at revision 10 at the time of writing...
Comment 2 Max 2014-07-26 11:39:30 UTC
I'm experiencing the same issue. I'm compiling on linux with ndk version 10. I'm only using armeabi-v7a. A week or 2 ago I compiled mupdf on windows and those versions worked fine.
Comment 3 Robin Watts 2014-07-26 15:37:52 UTC
That sounds like they broke the ndk again :(

Try adding the following to platform/android/jni/mupf.c:

#include <stdlib.h>

float strtof (const char* str, char** endptr)
{
    return (float)strtod(str, endptr);
}

Hopefully that should solve the problem. Please let us know if it does.
Comment 4 Nick 2014-07-28 05:47:11 UTC
I got same issue and I add that method(strtof) at mupdf.c

but it still doesn't work

i use ndk-r10 on cygwin.

and i also have this follow problem when i'm doing ndk-build

---------------------------------------------------------------------------------
Android NDK: WARNING:jni/Android.mk:mupdfcore: LOCAL_LDLIBS is always ignored for static libraries
[armeabi-v7a] Compile thumb  : mupdfcore <= pdf-fontfile.c
jni/../../../source/pdf/pdf-fontfile.c:21:29: fatal error: gen_font_base14.h: No such file or directory
 #include "gen_font_base14.h"
                             ^
compilation terminated.
/cygdrive/e/android-ndk-r10/build/core/build-binary.mk:447: recipe for target 'obj/local/armeabi-v7a/objs/mupdfcore/__/__/__/source/pdf/pdf-fontfile.o' failed
make: *** [obj/local/armeabi-v7a/objs/mupdfcore/__/__/__/source/pdf/pdf-fontfile.o] Error 1
---------------------------------------------------------------------------------
Comment 5 Nick 2014-07-28 06:02:09 UTC
please ignore following problem. my mistake.
anyway strtof issue still bother me
Comment 6 Ken Sharp 2014-07-30 06:04:00 UTC
*** Bug 695398 has been marked as a duplicate of this bug. ***
Comment 7 Jitesh Lalwani 2014-07-30 06:05:38 UTC
(In reply to Ken Sharp from comment #6)
> *** Bug 695398 has been marked as a duplicate of this bug. ***

Hi @Ken, So is this bug not resolved yet?
Comment 8 Ken Sharp 2014-07-30 06:22:03 UTC
(In reply to Jitesh Lalwani from comment #7)
> (In reply to Ken Sharp from comment #6)
> > *** Bug 695398 has been marked as a duplicate of this bug. ***
> 
> Hi @Ken, So is this bug not resolved yet?

If it was resolved the bug would be marked as such. I am not an Android developer, but it 'looks like' Google have broken the Android NDK again. But I don't know.
Comment 9 Jitesh Lalwani 2014-07-30 06:24:41 UTC
Hi Ken,

Thanks for the reply! Can we build using old Android NDK version? And will it create any problem as such?
Comment 10 Ken Sharp 2014-07-30 06:33:04 UTC
(In reply to Jitesh Lalwani from comment #9)

> Thanks for the reply! Can we build using old Android NDK version? And will
> it create any problem as such?

As I said, I am not an Android developer, I can't answer this question.
Comment 11 Matt Holgate 2014-07-30 07:29:01 UTC
NDK r10 works fine for me on Mac OS X.

Please could you try NDK r9d instead? You can download older versions of the NDK by editing the URL for the latest version and changing the version number.

Make sure you do an "ndk-build clean" before building after changing the version of the NDK.

Please let us know if this works for you.
Comment 12 Jitesh Lalwani 2014-07-30 23:14:05 UTC
(In reply to Matt Holgate from comment #11)
> NDK r10 works fine for me on Mac OS X.
> 
> Please could you try NDK r9d instead? You can download older versions of the
> NDK by editing the URL for the latest version and changing the version
> number.
> 
> Make sure you do an "ndk-build clean" before building after changing the
> version of the NDK.
> 
> Please let us know if this works for you.

Hi Matt thanks for replying but unfortunately changing the link to http://dl.google.com/android/ndk/android-ndk64-r9d-linux-x86_64.tar.bz2 does not download anything
Comment 13 Matt Holgate 2014-07-31 03:34:03 UTC
I'll just try a linux myself build with ndk r10...
Comment 14 Jitesh Lalwani 2014-07-31 03:36:30 UTC
(In reply to Matt Holgate from comment #13)
> I'll just try a linux myself build with ndk r10...

Hi Matt,

I just now tried with older version ( http://dl.google.com/android/ndk/android-ndk-r9d-linux-x86_64.tar.bz2 ) but m still getting following error:

07-31 16:04:44.370: E/AndroidRuntime(12771): Process: com.artifex.mupdfdemo, PID: 12771
07-31 16:04:44.370: E/AndroidRuntime(12771): java.lang.UnsatisfiedLinkError: Couldn't load mupdf from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.artifex.mupdfdemo-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.artifex.mupdfdemo-1, /vendor/lib, /system/lib]]]: findLibrary returned null
Comment 15 Matt Holgate 2014-07-31 04:37:52 UTC
This is odd. It works fine for me with the following configuration:

   - Linux (Ubuntu 10.04.4 LTS)
   - NDK r10 
   - SDK 16

I've tested the built APK on both a stock Nexus 5 running 4.4.4 and an emulator.

What kind of device are you testing on? I have seen these kind of problems with other projects on some HTC devices, although I never fully managed to get to the bottom of them.

Can you confirm if the build still fails when running in the emulator?

Thanks.
Comment 16 Jitesh Lalwani 2014-07-31 06:06:02 UTC
(In reply to Matt Holgate from comment #15)
> This is odd. It works fine for me with the following configuration:
> 
>    - Linux (Ubuntu 10.04.4 LTS)
>    - NDK r10 
>    - SDK 16
> 
> I've tested the built APK on both a stock Nexus 5 running 4.4.4 and an
> emulator.
> 
> What kind of device are you testing on? I have seen these kind of problems
> with other projects on some HTC devices, although I never fully managed to
> get to the bottom of them.
> 
> Can you confirm if the build still fails when running in the emulator?
> 
> Thanks.

Hi Matt,

I have tested on Moto G and Samsung tab. But I have a query here, if you were able to build on ubuntu, can you provide the source code files?
Comment 17 Matt Holgate 2014-07-31 06:07:02 UTC
(In reply to Jitesh Lalwani from comment #16)

> I have tested on Moto G and Samsung tab. But I have a query here, if you
> were able to build on ubuntu, can you provide the source code files?

Do you mean the APK? I can certainly provide that.
Comment 18 Jitesh Lalwani 2014-07-31 06:08:40 UTC
(In reply to Matt Holgate from comment #17)
> (In reply to Jitesh Lalwani from comment #16)
> 
> > I have tested on Moto G and Samsung tab. But I have a query here, if you
> > were able to build on ubuntu, can you provide the source code files?
> 
> Do you mean the APK? I can certainly provide that.

No I mean Java classes as I have to use it as library i.e. mupdf/platform/android
Comment 19 Matt Holgate 2014-07-31 06:34:49 UTC
No problem. I've sent you an email with a link to download the files.
Comment 20 Jitesh Lalwani 2014-07-31 07:10:28 UTC
(In reply to Matt Holgate from comment #19)
> No problem. I've sent you an email with a link to download the files.

Its working! Thanks a lot Matt, I wonder what was wrong in my build
Comment 21 Matt Holgate 2014-07-31 07:11:29 UTC
Cool! Glad to hear it is working.

Did you try an ndk-build clean / ant clean btw?
Comment 22 Jitesh Lalwani 2014-07-31 07:13:02 UTC
(In reply to Matt Holgate from comment #21)
> Cool! Glad to hear it is working.
> 
> Did you try an ndk-build clean / ant clean btw?

Yes infact I deleted everything started from ground zero
Comment 23 Matt Holgate 2014-07-31 07:14:27 UTC
Very weird. I'd be interested to know if you ever discover what the problem is!
Comment 24 Jitesh Lalwani 2014-07-31 07:20:30 UTC
(In reply to Matt Holgate from comment #23)
> Very weird. I'd be interested to know if you ever discover what the problem
> is!

Sure Matt. BTW I got one more crash. I just marked the code given by you as library and included in my project but it is crashing when I called as follows:

 Intent intent = new Intent(this, MuPDFActivity.class);

		 intent.setAction(Intent.ACTION_VIEW);

		 intent.setData(uri);

		 startActivity(intent);

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mupdfsample/com.artifex.mupdfdemo.MuPDFActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class android.support.v7.internal.widget.ActionBarView
Comment 25 Matt Holgate 2014-07-31 07:25:31 UTC
Ah, do you have the Android support library (http://developer.android.com/tools/support-library/index.html) added as a dependency of your project? It looks like we are trying to use it, but can't find its resources.
Comment 26 Jitesh Lalwani 2014-07-31 07:32:35 UTC
(In reply to Matt Holgate from comment #25)
> Ah, do you have the Android support library
> (http://developer.android.com/tools/support-library/index.html) added as a
> dependency of your project? It looks like we are trying to use it, but can't
> find its resources.

Hi Matt,

I have removed support for lower devices and it is working fine now :) Thanks for your great support!
Comment 27 Matt Holgate 2014-07-31 07:42:06 UTC
Cool, no problem, thanks!
Comment 28 Jitesh Lalwani 2014-08-04 06:17:47 UTC
(In reply to Matt Holgate from comment #27)
> Cool, no problem, thanks!

Hi Matt,I again got that problem today:

08-04 18:45:37.520: E/AndroidRuntime(10157): java.lang.UnsatisfiedLinkError: Native method not found: com.c2cdroid.main.MuPDFCore.openFile:(Ljava/lang/String;)J
Comment 29 Jitesh Lalwani 2014-08-04 06:18:55 UTC
(In reply to Matt Holgate from comment #27)
> Cool, no problem, thanks!

I have just changed the package name
Comment 30 Robin Watts 2014-08-04 09:07:49 UTC
(In reply to Jitesh Lalwani from comment #29)
> (In reply to Matt Holgate from comment #27)
> > Cool, no problem, thanks!
> 
> I have just changed the package name

Then you need to change the packagename in platform/android/jni/mupdf.c too.
Comment 31 Jitesh Lalwani 2014-08-04 23:16:42 UTC
(In reply to Robin Watts from comment #30)
> (In reply to Jitesh Lalwani from comment #29)
> > (In reply to Matt Holgate from comment #27)
> > > Cool, no problem, thanks!
> > 
> > I have just changed the package name
> 
> Then you need to change the packagename in platform/android/jni/mupdf.c too.

Hi Matt,

I have changed com/artifex/mupdfdemo to com/c2cdroid/main but am still getting the crash. Do I need to compile somthing after making the change and how, since you have provided me the source code as it was building on my side?
Comment 32 Avinash N 2014-08-10 08:47:47 UTC
Hi Matt,

I'm having the exact same issue as described here. Tried it in
- MAC OSX 10.9.3 & Archlinux 
- NDK r10 & r8b(earlist i could get)
- SDK 16

Had same issue across all environments. I see in the comments that Jitesh could make it work after you gave him the java files. It would be great if you could share the same with me. 

Thanks
Comment 33 Avinash N 2014-08-10 22:50:53 UTC
Hi Matt,
Nevermind, Jitesh gave me the files. Thanks
Comment 34 Matt Holgate 2014-08-11 02:28:18 UTC
Hi Avinash - cool.

It'd be good if we could fix the root cause though. I'm still unsure what is happening here :-(.
Comment 35 Avinash N 2014-08-11 02:44:21 UTC
Hi Matt, Let me know if you need any info on the problem. I can send the entire project (that did not) to you, if you wish.
Comment 36 Tor Andersson 2014-10-02 10:44:39 UTC
You need to use the NDK for 32-bit target platforms if you're targeting a 32-bit platform. The NDK for 64-bit target platforms builds broken binaries for 32-bit targets.

*** This bug has been marked as a duplicate of bug 695488 ***