barteksc / AndroidPdfViewerV2

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
128 stars 75 forks source link

do you have it on Xamarin? #9

Open GitBasil opened 5 years ago

GitBasil commented 5 years ago

please create one for xamarin native android

scarabdesign commented 5 years ago

For those interested, I am attempting to make a C# wrapper for this library with Visual Studio to use in Xamarin. I'm running into problems.

I started out by creating a binding project (https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-an-aar). I was able to update the Gradle plug-in to the latest and get a "Release" build complete. I imported the resulting AAR (android-pdf-viewer-release.aar) into a new VS project and followed the instructions on building it. I then imported it into my main project in VS.

The reference shows up in the list and I'm able to open it in the Object Browser and I pretty well see everything. When writing the code, the auto-complete feature of VS seems to find all the paths just fine. I added the element to the layout as the AndroidPdfViewerV2 instructions suggest, and again the auto-complete when adding the element into the axml file found the correct path ("com.github.barteksc.pdfviewer.PDFView").

My project builds, and runs, but when I try to open a pdf it gets stuck here:

Android.Views.InflateException: 'Binary XML file line #1: Binary XML file line #1: Error inflating class com.github.barteksc.pdfviewer.PDFView'

Any help in this would be appreciated.

scarabdesign commented 5 years ago

The above issue was because I didn't also wrap the core library (PdfiumAndroid) that this library accesses. So I did the same with it (https://github.com/barteksc/PdfiumAndroid) and imported into my project. This solves my previous error, now I'm getting another error:

06-20 17:56:12.907 E/com.shockwave.pdfium.PdfiumCore(14226): Native libraries failed to load - java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "[...]==/base.apk"],nativeLibraryDirectories=[/[...]==/lib/arm64,[...]==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]] couldn't find "libc++_shared.so"
06-20 17:56:12.910 D/com.shockwave.pdfium.PdfiumCore(14226): Starting PdfiumAndroid 1.9.0
06-20 17:56:12.943 D/ConnectivityManager(14226): requestNetwork; CallingUid : 10320, CallingPid : 14226
06-20 17:56:12.946 D/ConnectivityManager(14226): requestNetwork; CallingUid : 10320, CallingPid : 14226
06-20 17:56:12.973 W/etua.ERPXamari(14226): Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, reflection)
06-20 17:56:12.973 E/etua.ERPXamari(14226): No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String) (tried Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument and Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)
06-20 17:56:12.995 E/PDFView (14226): load pdf error
06-20 17:56:12.995 E/PDFView (14226): java.lang.UnsatisfiedLinkError: No implementation found for long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int, java.lang.String) (tried Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument and Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)
06-20 17:56:12.995 E/PDFView (14226):   at com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(Native Method)
06-20 17:56:12.995 E/PDFView (14226):   at com.shockwave.pdfium.PdfiumCore.newDocument(PdfiumCore.java:135)
06-20 17:56:12.995 E/PDFView (14226):   at com.github.barteksc.pdfviewer.source.FileSource.createDocument(FileSource.java:38)
06-20 17:56:12.995 E/PDFView (14226):   at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:49)
06-20 17:56:12.995 E/PDFView (14226):   at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:25)
06-20 17:56:12.995 E/PDFView (14226):   at android.os.AsyncTask$2.call(AsyncTask.java:333)
06-20 17:56:12.995 E/PDFView (14226):   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
06-20 17:56:12.995 E/PDFView (14226):   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
06-20 17:56:12.995 E/PDFView (14226):   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
06-20 17:56:12.995 E/PDFView (14226):   at java.lang.Thread.run(Thread.java:764)
scarabdesign commented 5 years ago

I figured this out an posted about it here: https://github.com/barteksc/AndroidPdfViewer/issues/782#issuecomment-516654840