本文介绍了尝试为PDFTron Android加载loadLibrary时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试与PDFTron(即PDFNet Android SDK)集成时遇到一个奇怪的错误:

I am getting a strange error when trying to integrate with PDFTron i.e PDFNet Android SDK:

我已经检查了此链接.

PDFNet Android SDK提供的本机库很可能未正确包含在我的项目中.在已下载软件包的lib文件夹中,有本机库和Java库,都需要包含在我的项目中.

Most likely the native library provided by PDFNet Android SDK is not included in my project correctly.Inside the lib folder I the downloaded package, there are native libraries and java library that both need to be included to my project.

在主文件夹中创建一个名为jniLibs的文件夹,并将所有.so(具有相应的文件夹结构)放在jniLibs文件夹中,即:

Created a folder called jniLibs in main folder and place all .so (with corresponding folder structure) inside the jniLibs folder, i.e.:

这将允许Android Studio自动识别本机库路径.

This will allow Android Studio to automatically recognize the native library path.

我还指定了产品口味来过滤要使用的.so,例如:

I also specified product flavor to filter which .so to use, such as:

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目录,即:

Then I specified the jniLibs directory inside build.gradle file of your project, i.e.:

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').

Import PDFTron Library Project in Android Studio.Use that Library Project in your application.For this use compile project(':libraries:PDFViewCtrlTools') in your application's build.gradle.

现在将libPDFNetC.so文件复制到应用程序中的"jni/libs/armeabi"文件夹中.

Now copy libPDFNetC.so file to "jni/libs/armeabi" folder in your application.

在您的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.

may be by using this method you can open PDF from url.

代码:

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"/>

这篇关于尝试为PDFTron Android加载loadLibrary时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:50