首页 > 编程知识 正文

MuPDF 开源PDF库编译过程记录,动态库编译过程

时间:2023-05-06 12:49:56 阅读:227116 作者:2468

最近工作中需要开发一个PDF阅读的功能,开始选择了Android-pdfview开源组件,但是有些PDF文件打开会crash,这个开源组件没有提供jni代码,只能在java层进行捕获,还是无法解决打不开某些pdf文件的问题;只能另寻他家;在网上转了一圈,貌似可行的开源库有pdfbox,iText和MuPDF;最终选择MuPDF做尝试;从github找到了一个demo,运行了一下,前面打不开的pdf文件,使用该库可以代码,并且该库的加载速度和流畅性都由于前者;特意观察了一下内存,发现并没有耗内存的情况,可以放心尝试了;

抱着学习的态度,暂时不选择直接使用这个demo,尝试从MuPDF官网下载原代码自己编译(对NDK这块我还是比较生疏的,只写过一些简单的库);

下面主要记录一下MuPDF源代码编译过程以及遇到的问题和解决办法;

先贴出官网编译指导:

Set up an Android build environment

Download and install the Android SDK. Run the android tool to install the platform tools. Add the tools and platform-tools directories inside the SDK directory to your PATH.

Download and install the Android NDK (r6 or later). Use the 32-bit target NDK if targeting a 32-bit platform! Add the NDK directory to your PATH.

Make sure you have both JDK and ANT installed.

You will also need git and a regular development environment (gcc and gnu make).

Prepare the source

Check out a copy of the mupdf source from git:

~/src $ git clone git://git.ghostscript.com/mupdf.git

Check out the third party library submodules:

~/src/mupdf $ git submodule update --init

Populate the generated directory with the necessary files:

~/src/mupdf $ make generate Build and debug

Change into the platform/android/viewer directory and edit the local properties configuration file.

~/src/mupdf $ cd platform/android/viewer~/src/mupdf/platform/android/viewer $ cp local.properties.sample local.properties~/src/mupdf/platform/android/viewer $ nano local.properties

Build the native code libraries:

~/src/mupdf/platform/android/viewer $ ndk-build

Build the java application:

~/src/mupdf/platform/android/viewer $ ant debug

Install the app on the device or emulator:

~/src/mupdf/platform/android/viewer $ ant debug install

Copy some files onto the device for the app to read:

~/src/mupdf/platform/android/viewer $ adb push .../file.pdf /mnt/sdcard/Download/file.pdf

To see debug messages from the emulator:

~/src/mupdf/platform/android/viewer $ adb logcat

Good luck!


基本的编译流程就是按官网指导来,但是也有一些需要特意说明的地方;

1、我是在windows上编译的,所以必须安装cygwin,选择“devel”和“shells”进行安装(gcc and gnu make);因为只有安装了cygwin,才能执行make命令;

2,在执行ndk-build时遇到了问题,报错了;参考http://www.gezila.com/tutorials/11080.html文章,但是还是报错;最终的解决办法:

首先,修改local.properties文件内容为

sdk.dir=C:\Documents and Settings\Administrator\android-sdks\platforms\android-10

   ndk.dir=C:\android-ndk-r8b

   分别是android sdk 路径和ndk 路径;

再就是看mupdfplatformandroidviewerjni下的Application.mk文件最下面的内容:

# If the ndk is r8b then workaround bug by uncommenting the following line
#NDK_TOOLCHAIN_VERSION=4.4.3
# If the ndk is newer than r8c, try using clang.
#NDK_TOOLCHAIN_VERSION=clang3.1

对照自己的ndk版本,选择放开哪一行代码,但不是必须的;

我的ndk版本是r10e,所以一开始选择放开NDK_TOOLCHAIN_VERSION=clang3.1,但是不行报错了,如下:

$ ndk-buildAndroid NDK: WARNING:jni/Android.mk:mupdfcore: LOCAL_LDLIBS is always ignored fo r static libraries[armeabi-v7a] Cygwin : Generating dependency file converter script[armeabi-v7a] Compile : mupdf_java <= mupdf.c/lldlq/sh: /cygdrive/d/Android/android-ndk-r10e/toolchains/arm-linux-androideabi-c lang3.1/prebuilt/windows/lldlq/arm-linux-androideabi-gcc: No such file or director y/cygdrive/d/Android/android-ndk-r10e/build/core/build-lldlqary.mk:464: recipe for target 'obj/local/armeabi-v7a/objs/mupdf_java/mupdf.o' failedmake: *** [obj/local/armeabi-v7a/objs/mupdf_java/mupdf.o] Error 127对照报错日志看了下我的ndk目录,发现确实没有android-ndk-r10e/toolchains/arm-linux-androideabi-c lang3.1/这个目录,然后就想到Application.mk中放开的那段代码了,就是这段代码指定的这个目录;所以我尝试又把这段代码注释掉,再编译竟然通过了;

如果你也遇到同样的问题,可以尝试我的方法,也可以看下自己toolchains目录下的目录,对照目录尝试修改Application.mk文件中NDK_TOOLCHAIN_VERSION=clang3.1这段代码中指定的clang版本号;


先到这里!

为android平台已编译好的1.8和1.9a版本源代码即demo下载地址:https://github.com/ZhangSir/mupdf-source

win7中qq截图快捷键是什么

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。