简体   繁体   中英

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

After signing the APK, the app crashes when I try to open any 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

-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

The second issue is the size of the final signed APK. The size moved from 3.2MB to 10.7MB after including the library. 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. I was advised to add this

LOCAL_CFLAGS += -DNOCJK

in Core.mk. to exclude fonts from .so. This is how my final Core.mk looked like

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

The issue was actually not with mupdf, It was a null pointer exception on onCreateOptionsMenu method in my PdfViewActivity.java. I had to add

debuggable true

in my app gradle to know where the problem was.

I changed my proguard file to the following and I was able to sort the problem:

-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

I was able to solve this by adding

LOCAL_CFLAGS += -DNOCJK

still in Core.mk but immediately after

MY_ROOT := ../..

I hope this helps someone who might face the same problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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