Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating MuPDF as a library project (Android)

So I have built this project based on a pdf reader(MuPDF). I used ndk-build for that. The name of this project is ChoosePDFActivity. I know that it has been correctly built because I can see a .so file inside my libs/armrabi-v7a/THISISTHEFILE.so. My question is, how do i Correctly make this project a library project and run it from another project ?

I tried marking it as a library project and adding it to my main project's build path, but I get

Note that I am using Mupdf-1.5(the latest one currently)

ExpressionInitializerError , could not load library , FindLibrary Returned NUll errors

so what do I do ?

the name of my library is libmupdf. Note, I am new to android-ndk. I dont have any jni folder in my main project, only in the library project. This is the full error.

06-16 17:51:27.680: E/AndroidRuntime(5673): FATAL EXCEPTION: main 06-16 17:51:27.680: E/AndroidRuntime(5673): java.lang.ExceptionInInitializerError 06-16 17:51:27.680: E/AndroidRuntime(5673): at java.lang.Class.newInstanceImpl(Native Method) 06-16 17:51:27.680: E/AndroidRuntime(5673): at java.lang.Class.newInstance(Class.java:1319) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.app.Instrumentation.newActivity(Instrumentation.java:1025) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.app.ActivityThread.access$600(ActivityThread.java:123) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.os.Handler.dispatchMessage(Handler.java:99) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.os.Looper.loop(Looper.java:137) 06-16 17:51:27.680: E/AndroidRuntime(5673): at android.app.ActivityThread.main(ActivityThread.java:4424) 06-16 17:51:27.680: E/AndroidRuntime(5673): at java.lang.reflect.Method.invokeNative(Native Method) 06-16 17:51:27.680: E/AndroidRuntime(5673): at java.lang.reflect.Method.invoke(Method.java:511) 06-16 17:51:27.680: E/AndroidRuntime(5673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825) 06-16 17:51:27.680: E/AndroidRuntime(5673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592) 06-16 17:51:27.680: E/AndroidRuntime(5673): at dalvik.system.NativeStart.main(Native Method) 06-16 17:51:27.680: E/AndroidRuntime(5673): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load libmupdf: findLibrary returned null 06-16 17:51:27.680: E/AndroidRuntime(5673): at java.lang.Runtime.loadLibrary(Runtime.java:365) 06-16 17:51:27.680: E/AndroidRuntime(5673): at java.lang.System.loadLibrary(System.java:535) 06-16 17:51:27.680: E/AndroidRuntime(5673): at com.mainpackage.MainActivity.(MainActivity.java:44)

Please help me, its killing me for a couple of days. Thanks in advance.

this is my Android.mk:

LOCAL_PATH := $(call my-dir)
TOP_LOCAL_PATH := $(LOCAL_PATH)

MUPDF_ROOT := ../..

ifdef NDK_PROFILER
include android-ndk-profiler.mk
endif

include $(TOP_LOCAL_PATH)/Core.mk
include $(TOP_LOCAL_PATH)/ThirdParty.mk

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := \
    jni/andprof \
    $(MUPDF_ROOT)/include \
    $(MUPDF_ROOT)/source/fitz \
    $(MUPDF_ROOT)/source/pdf
LOCAL_CFLAGS :=
LOCAL_MODULE    := mupdf
LOCAL_SRC_FILES := mupdf.c
LOCAL_STATIC_LIBRARIES := mupdfcore mupdfthirdparty
ifdef NDK_PROFILER
LOCAL_CFLAGS += -pg -DNDK_PROFILER
LOCAL_STATIC_LIBRARIES += andprof
else
endif

LOCAL_LDLIBS    := -lm -llog -ljnigraphics
ifdef SSL_BUILD
LOCAL_LDLIBS    += -L$(MUPDF_ROOT)/thirdparty/openssl/android -lcrypto -lssl
endif

include $(BUILD_SHARED_LIBRARY)

Here is a snapshot of my projects.There are two highlighted projects, they are the ones being talked about, with ChoosePDFActivity being the library project. enter image description here, Okay, just something like this is going to work for my case: Is it possible to have a Whole project inside my final build?I just need to pass ONE intent to it from my main project, and everything else is going to be handled by the ChoosePdf... project.

P.S. I noticed that there is a armeabi-v7a only. So , is there any way to build mupdf for other architectures as well

EDIT For those who want to have PDF rendering in android, Android L has (finally) got the apis to make native pdf rendering possible.

like image 723
harveyslash Avatar asked Jun 16 '14 12:06

harveyslash


1 Answers

You just have to create a dummy dynamic library that simply links against your static library like this:

https://stackoverflow.com/a/2957386/892714

The ndk build system (unfortunately) will not create a static library without it being used by a dynamic library. Then you simply grab your static library from obj/local/armeabi-v7a.

like image 98
JonnyBoy Avatar answered Oct 06 '22 03:10

JonnyBoy