简体   繁体   English

如何在Android中使用mupdf库

[英]How to use mupdf library in Android

I have built mupdf from source following these steps http://www.mupdf.com/docs/how-to-build-mupdf-for-android . 我已按照以下步骤从源代码构建了mupdf :http://www.mupdf.com/docs/how-to-build-mupdf-for-android I have integrated it in my app and it is working fine. 我已经将其集成到我的应用程序中,并且工作正常。

I am however facing some issues that I would like input from anyone and I would greatly appreciate 但是,我遇到了一些问题,希望得到任何人的帮助,我将不胜感激

Issue #1 第1期

After signing the APK, the app crashes when I try to open any pdf. 对APK签名后,当我尝试打开任何pdf时,应用程序崩溃。 My guess is some classes are been omitted during the process. 我的猜测是在此过程中省略了一些类。 I googled and this is the closest answer I came about but it did not work for me. 我用谷歌搜索, 是我得到的最接近的答案,但是它对我没有用。 This is how my proguard-rules.pro file looks like 这就是我的proguard-rules.pro文件的样子

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontoptimize
-dontpreverify


-dontwarn com.squareup.picasso.**
-dontwarn com.android.volley.**
-dontwarn com.nhaarman.listviewanimations.**
-dontwarn android.support.**


-keep class com.artifex.mupdfdemo.** { *; }
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v7.app.** { *; }
-keep interface android.support.v7.app.** { *; }

Issue #2 第2期

The second issue is the size of the final signed APK. 第二个问题是最终已签名APK的大小。 The size moved from 3.2MB to 10.7MB after including the library. 包含库后,大小从3.2MB移至10.7MB。 I sought advice from IRC #ghostscript channel but the solution did not solve my problem, may be I missed something in the course of implementation. 我从IRC #ghostscript渠道寻求建议,但该解决方案未能解决我的问题,可能是我在实施过程中错过了一些东西。 I was advised to add this 建议我添加此

LOCAL_CFLAGS += -DNOCJK LOCAL_CFLAGS + = -DNOCJK

in Core.mk. 在Core.mk中。 to exclude fonts from .so. 从.so中排除字体。 This is how my final Core.mk looked like 这就是我最终的Core.mk的样子

LOCAL_PATH := $(call my-dir)

ifdef SUPPORT_GPROOF
include $(CLEAR_VARS)
LOCAL_MODULE    := gsso
LOCAL_SRC_FILES := libgs.so
include $(PREBUILT_SHARED_LIBRARY)
endif

include $(CLEAR_VARS)

MY_ROOT := ../..

ifeq ($(TARGET_ARCH),arm)
LOCAL_CFLAGS += -DARCH_ARM -DARCH_THUMB -DARCH_ARM_CAN_LOAD_UNALIGNED
ifdef NDK_PROFILER
LOCAL_CFLAGS += -pg -DNDK_PROFILER
endif
endif
ifdef SUPPORT_GPROOF
LOCAL_CFLAGS += -DSUPPORT_GPROOF
endif
LOCAL_CFLAGS += -DAA_BITS=8
ifdef MEMENTO
LOCAL_CFLAGS += -DMEMENTO -DMEMENTO_LEAKONLY
endif
ifdef SSL_BUILD
LOCAL_CFLAGS += -DHAVE_OPENSSL
LOCAL_CFLAGS += -DNOCJK
endif

LOCAL_C_INCLUDES := \
    ../../thirdparty/jbig2dec \
    ../../thirdparty/openjpeg/libopenjpeg \
    ../../thirdparty/jpeg \
    ../../thirdparty/mujs \
    ../../thirdparty/zlib \
    ../../thirdparty/freetype/include \
    ../../source/fitz \
    ../../source/pdf \
    ../../source/xps \
    ../../source/cbz \
    ../../source/img \
    ../../source/tiff \
    ../../scripts/freetype \
    ../../scripts/jpeg \
    ../../scripts/openjpeg \
    ../../generated \
    ../../resources \
    ../../include \
    ../..
ifdef V8_BUILD
LOCAL_C_INCLUDES += ../../thirdparty/$(V8)/include
endif
ifdef SSL_BUILD
LOCAL_C_INCLUDES += ../../thirdparty/openssl/include
endif

LOCAL_MODULE    := mupdfcore
LOCAL_SRC_FILES := \
    $(wildcard $(MY_ROOT)/source/fitz/*.c) \
    $(wildcard $(MY_ROOT)/source/pdf/*.c) \
    $(wildcard $(MY_ROOT)/source/xps/*.c) \
    $(wildcard $(MY_ROOT)/source/cbz/*.c) \
    $(wildcard $(MY_ROOT)/source/gprf/*.c) \
    $(wildcard $(MY_ROOT)/source/html/*.c)
LOCAL_SRC_FILES += \
    $(MY_ROOT)/source/pdf/js/pdf-js.c \
    $(MY_ROOT)/source/pdf/js/pdf-jsimp-mu.c

ifdef SUPPORT_GPROOF
LOCAL_SHARED_LIBRARIES := gsso
endif
LOCAL_LDLIBS    := -lm -llog -ljnigraphics

LOCAL_SRC_FILES := $(addprefix ../, $(LOCAL_SRC_FILES))

include $(BUILD_STATIC_LIBRARY)

Any help or guidance will be greatly appreciated. 任何帮助或指导将不胜感激。

Thanks 谢谢

So after spending some time on my two issues, I managed to finally solve them: 因此,在花了一些时间解决我的两个问题之后,我终于解决了它们:

Issue #1 第1期

The issue was actually not with mupdf, It was a null pointer exception on onCreateOptionsMenu method in my PdfViewActivity.java. 问题实际上与mupdf无关,这是我的PdfViewActivity.java中onCreateOptionsMenu方法的空指针异常。 I had to add 我必须添加

debuggable true 可调试true

in my app gradle to know where the problem was. 在我的应用程序gradle中知道问题出在哪里。

I changed my proguard file to the following and I was able to sort the problem: 我将我的proguard文件更改为以下文件,并能够对问题进行排序:

-ignorewarnings
-optimizationpasses 2
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-keepclasseswithmembernames class * {
    native <methods>;
}
-keep public class com.artifex.mupdfdemo.* {*;}

-dontwarn com.squareup.picasso.**
-dontwarn com.android.volley.**
-dontwarn com.nhaarman.listviewanimations.**
-dontwarn android.support.**



-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }

Issue #2 第2期

I was able to solve this by adding 我可以通过添加解决

LOCAL_CFLAGS += -DNOCJK LOCAL_CFLAGS + = -DNOCJK

still in Core.mk but immediately after 仍然在Core.mk中,但之后

MY_ROOT := ../.. MY_ROOT:= ../ ..

I hope this helps someone who might face the same problem 我希望这可以帮助可能遇到相同问题的人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM