尝试与 PDFTron(即 PDFNet Android SDK)集成时遇到奇怪的错误:
UnsatisfiedLinkError: Couldn't load PDFNetC: findLibrary returned null. Expected armv7a, found cpu_info: abi: armeabi-v7a
我已经检查过这个link .
很可能 PDFNet Android SDK 提供的 native 库未正确包含在我的项目中。 在我下载的包的 lib 文件夹中,有 native 库和 java 库,它们都需要包含到我的项目中。
在主文件夹中创建一个名为jniLibs的文件夹,并将所有.so(具有相应的文件夹结构)放入jniLibs文件夹中,即:
这将允许 Android Studio 自动识别 native 库路径。
我还指定了产品 flavor 来过滤要使用的.so,例如:
productFlavors {
armv7a {
ndk {
abiFilters "armeabi-v7a"
}
}
arm {
ndk {
abiFilters "armeabi"
}
}
x86 {
ndk {
abiFilters "x86"
}
}
armv8 {
ndk {
abiFilters "arm64-v8a"
}
}
x86_64 {
ndk {
abiFilters "x86_64"
}
}
fat {
ndk {
abiFilters "armeabi-v7a", "armeabi", "arm64-v8a", "x86", "x86_64"
}
}
}
然后我在项目的 build.gradle 文件中指定了 jniLibs 目录,即:
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
jniLibs.srcDirs = ['libs']
svg.srcDir 'src/main/svg'
}
}
最佳答案
在 Android Studio 中导入 PDFTron 库项目。
在您的应用程序中使用该库项目。为此,请在应用程序的 build.gradle
中使用 compile project(':libraries:PDFViewCtrlTools')
。
现在将 libPDFNetC.so
文件复制到应用程序中的“jni/libs/armeabi”文件夹。
在您的application.mk
中写入此内容。
APP_ABI := armeabi-v7a
APP_CPPFLAGS += -std=c++11 -exception
APP_STL := gnustl_shared
APP_PLATFORM=android-19
APP_OPTIM := debug
NDK_TOOLCHAIN_VERSION := 4.8
在您的 Android.mk
文件中添加此内容
include $(CLEAR_VARS)
LOCAL_MODULE := libPDFNetC
# this libs path is relative to my jni files, so, src/main/jni/libs/libPrecompiledLib.a
LOCAL_SRC_FILES := libs/armeabi/libPDFNetC.so
include $(PREBUILT_SHARED_LIBRARY)
编辑:
PDFDoc doc = PDFDoc(InputStream var1)
也许通过使用此方法,您可以从 url 打开 PDF。
代码:
PDFViewCtrl mPDFViewCtrl = (PDFViewCtrl) view.findViewById(R.id.pdfViewer);
PDFDoc doc = new PDFDoc(filePath);
mPDFViewCtrl.setDoc(doc);
xml
<pdftron.PDF.PDFViewCtrl
android:id="@+id/pdfViewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical|horizontal"
android:visibility="gone"/>
关于java - 尝试加载 PDFTron Android 库时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41295909/