提问者:小点点

kotlin androidpdfviewer库似乎没有加载


我正在使用android pdfviewer lib来打开和阅读pdf,可以在以下网址找到:https://github.com/barteksc/androidPDFViewer

但当我尝试启动pdf时出现了一个错误:

E/Zygote64:找不到长com.shockwave.pdfium.pdfiumcore.NativeOpendocument(int,java.lang.String)的实现(尝试了Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument和Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)

E/pdfview:加载pdf错误java.lang.UnsatisfiedLinkError:找不到长com.shockwave.pdfium.pdfiumcore.NativeOpendocument(int,java.lang.string)的实现(尝试了Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument和Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2)

我尝试了依赖项的不同实现,但没有一个有效:

implementation 'com.github.barteksc:pdfium-android:1.9.0'
implementation "com.github.barteksc:android-pdf-viewer:3.2.0-beta.1"
implementation "com.github.barteksc:android-pdf-viewer:2.8.2"

错误出现在以下位置:

public PdfDocument newDocument(ParcelFileDescriptor fd, String password) throws IOException {
        PdfDocument document = new PdfDocument();
        document.parcelFileDescriptor = fd;
        synchronized (lock) {
            document.mNativeDocPtr = nativeOpenDocument(getNumFd(fd), password);
        }

        return document;
    }

lib中的功能nativeOpenDocument似乎没有加载。

我在github上发现了一些关于它的话题:https://github.com/barteksc/androidpdfviewer/issues/538 https://github.com/barteksc/pdfiumandroid/issues/54 https://github.com/mshockwave/pdfiumandroid/issues/13

但是没有找到解决方案,我尝试改变依赖关系,尝试关闭我的计算机和电话,尝试使缓存无效并重新启动,尝试在模拟器上,但没有工作。

如果有人能帮我那就太好了?


共2个答案

匿名用户

下面是我加载pdf URL的方式:

fragment_pdf_reader.xml:

<androidx.constraintlayout.widget.ConstraintLayout
//....
<com.github.barteksc.pdfviewer.PDFView
            android:id="@+id/pdfView"
            android:layout_width="match_parent"
            android:layout_height="@dimen/zeroDp"
            android:visibility="visible"
            app:layout_constraintBottom_toTopOf="@+id/tvFeedback"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/view" />
//...
</androidx.constraintlayout.widget.ConstraintLayout>

现在,在您的片段中,获取pdf url并使用该pdf url发出Http请求,然后获取ResponseBody,将其传递给下面的方法:

private fun downloadFile(responseBody: ResponseBody) {// get responseBody after making Http req . I'm using retrofit 
        binding?.let {
            //it.pdfView.removeAllViews()
            it.pdfView.fromBytes(responseBody.bytes())
                    .defaultPage(pageNumber)
                    .onPageChange(this@PdfReaderFragment)
                    .enableAnnotationRendering(true)
                    .onLoad(this@PdfReaderFragment)
                    .spacing(10) // in dp
                    .onPageError(this@PdfReaderFragment)
                    .onError { onError("File not in PDF format or corrupted") }
                    .load()
        }


    }

实施以下回调:

OnPageChangeListener
OnLoadCompleteListener
OnPageErrorListener

上述回叫的实现方式为:

override fun loadComplete(nbPages: Int) {
        binding?.let {
            printBookmarksTree(it.pdfView.tableOfContents, "-")
        }

    }

override fun onPageError(page: Int, t: Throwable?) {
        Log.d("PDF", t?.message)
    }
override fun onPageChanged(page: Int, pageCount: Int) {
        pageNumber = page
        Log.d("PDF", "Page number $pageNumber $pageCount")
        setTitleMessageBackArrow(String.format("%s %s / %s", "your fragment title", page + 1, pageCount))
    }

    private fun printBookmarksTree(tree: List<Bookmark>, sep: String) {
        for (b in tree) {
            Log.e("PDF", String.format("%s %s, p %d", sep, b.title, b.pageIdx))
            if (b.hasChildren()) {
                printBookmarksTree(b.children, "$sep-")
            }
        }
    }

匿名用户

我刚刚发现,在我的例子中,我有一个应用程序和一个模块,其中有我自己的库aar,我在那里使用AndroidPDFViewer。

问题是我只依赖于lib而不是应用程序。

为了解决这个问题,我必须在应用程序和库中添加依赖项。 很明显现在我看到我有两个建筑。格雷德尔。 现在运转良好。