我正在使用android pdfviewer lib打开并阅读一个pdf,它位于:https://github.com/barteksc/AndroidPdfViewer
但是当我尝试启动pdf时,我得到了一个错误:
E/zygote64:找不到long com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int,的实现(尝试过Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument和Java_com_shockwave_pdfium_PdfiumCore_nativeOpenDocument__ILjava_lang_String_2) java.lang.String)
E/ com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(int,查看: load pdf error java.lang.String:找不到long pdf的实现)(已尝试使用pdf和pdf
我尝试了依赖的不同实现,但都不起作用:
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;
}库中的函数nativeOpenDocument似乎未加载。
我在github上找到了一些关于它的话题:https://github.com/barteksc/AndroidPdfViewer/issues/538 https://github.com/barteksc/PdfiumAndroid/issues/54 https://github.com/mshockwave/PdfiumAndroid/issues/13
但是没有找到解决方案,正如我所建议的那样,我试图改变依赖关系,试图关闭我的电脑和手机,试图使缓存失效并重新启动,在模拟器上尝试,但都没有效果。
如果有人能帮我的话就太好了?
发布于 2020-07-16 22:39:57
我刚刚发现,在我的例子中,我有一个应用程序和一个模块,其中是我自己的库aar,我在其中使用androidpdfviewer。
问题是我只依赖于lib而不是app。
为了解决这个问题,我必须在应用程序和库中都添加依赖项。现在我看到我有两个build.gradle,这似乎是显而易见的。现在它工作得很好。
在build.gradle中添加classpath 'com.github.barteksc:pdfium-android:1.9.0',但添加项目而不是模块。
发布于 2020-07-16 21:34:07
这是我加载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-")
}
}
}https://stackoverflow.com/questions/62935251
复制相似问题