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(H andler.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. 在这里输入图像描述 , 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.

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


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.


You do not really need any NDK magic because if your project has no jni/ folder, and if you place the libraries in the libs/ , they will be there. (Just in case, put them under version control; by default .so is usually ignored.)

The most important line in your log is:

Caused by: java.lang.UnsatisfiedLinkError: Couldn't load libmupdf

If your project uses two libraries, you have to load both, in the order that would resolve dependencies.

static {
    System.loadLibrary("tools"); // libtools.so
    System.loadLibrary("main"); // libmain.so
}

As I understand, you have no linker problems, but just in case I post these links:
Re: How to build an shared library and call it in other ndk program
Android NDK - make two native shared libraries calling each other
Android NDK: Link using a pre-compiled static library

链接地址: http://www.djcxy.com/p/21180.html

上一篇: 使用审计插入grails中的双记录

下一篇: 将MuPDF作为一个库项目(Android)