Search code examples
android.netxamarinxamarin.androidmupdf

Android, Attempting to view a PDF within my Xamarin android application using muPDF


I am attempting to view a PDF internally within my application using muPDF. I have followed theses instructions to install the package onto my project: https://www.nuget.org/packages/Askaiser.Android.MuPDF/

Here's how I implemented my code:

File file = (File)fileFromAsset(this, "test.pdf");
var uri = Android.Net.Uri.Parse(file.AbsolutePath);
var intent0 = new Intent(this, typeof(MuPDFActivity));
intent0.SetFlags(ActivityFlags.NoHistory);
intent0.SetAction(Intent.ActionView);
intent0.SetData(uri);
StartActivity(intent0); 

However, I keep encountering this error when I attempt to view the file:

Java.Lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file 
    "/data/app/Xamarin_MuPDF.Xamarin_MuPDF-1/base.apk"],
    nativeLibraryDirectories=[/data/app/Xamarin_MuPDF.Xamarin_MuPDF-1/lib/arm64, 
    /vendor/lib64, /system/lib64]]] couldn't find "libmupdf_java.so"

Can anyone help me resolve this issue please.

Thanks in advance.


Solution

  • The project only contains armv7 and x86 libraries:

    https://github.com/asimmon/MuPDF-for-Xamarin-Android/tree/master/src/Askaiser.Android.MuPDF/libs

    Your error message clearly shows the app trying to load an arm64 library, so it is not surprising that this fails.

    You need to either:

    1. Add arm64 libraries (or ask the project owner to)

    2. Remove arm64 support from your app; there is some help here: How to use 32-bit native libraries on 64-bit Android device (but I'm not sure exactly how you do that with Xamarin)