简体   繁体   English

将MuPDF集成为库项目(Android)

[英]Integrating MuPDF as a library project (Android)

So I have built this project based on a pdf reader(MuPDF). 所以我基于PDF阅读器(MuPDF)构建了这个项目。 I used ndk-build for that. 我使用了ndk-build。 The name of this project is ChoosePDFActivity. 这个项目的名称是ChoosePDFActivity。 I know that it has been correctly built because I can see a .so file inside my libs/armrabi-v7a/THISISTHEFILE.so . 我知道它已经正确构建,因为我可以在libs / armrabi-v7a / THISISTHEFILE.so中看到一个.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) 请注意,我使用的是Mupdf-1.5(目前最新的)

ExpressionInitializerError , could not load library , FindLibrary Returned NUll errors ExpressionInitializerError,无法加载库,FindLibrary返回NUll错误

so what do I do ? 那我该怎么办?

the name of my library is libmupdf. 我的库名是libmupdf。 Note, I am new to android-ndk. 注意,我是android-ndk的新手。 I dont have any jni folder in my main project, only in the library project. 我的主项目中没有任何jni文件夹,只在库项目中。 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 06-16 17:51:27.680:E / AndroidRuntime(5673):致命异常:主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):在android.app.Instrumentation.newActivity(Instrumentation.java:1025)06-16 17:51:27.680:E / AndroidRuntime(5673):在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):在android.app.ActivityThread.access $ 600(ActivityThread.java:123)06-16 17:51:27.680:E / AndroidRuntime(5673):在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 andler.java:99)06-16 17:51:27.680:E/AndroidRuntime(5673):atroid.os.Looper.loop(Looper.java:137)06-16 17:51:27.680:E/AndroidRuntime( 5673):在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):引起: java.lang.UnsatisfiedLinkError:无法加载libmupdf:findLibrary返回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) (5673):在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: 这是我的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. 这是我的项目的快照。有两个突出显示的项目,他们是被讨论的项目,ChoosePDFActivity是图书馆项目。 在此输入图像描述 , 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. 好吧,这样的事情对我的情况有用:是否有可能在我的最终构建中有一个整个项目?我只需要从我的主项目中传递一个意图,其他一切都将被处理通过ChoosePdf ...项目。

PS I noticed that there is a armeabi-v7a only. PS我注意到只有armeabi-v7a。 So , is there any way to build mupdf for other architectures as well 那么,有没有办法为其他架构构建mupdf

EDIT For those who want to have PDF rendering in android, Android L has (finally) got the apis to make native pdf rendering possible. 编辑对于那些想要在Android中进行PDF渲染的人来说,Android L(终于)获得了使本机pdf渲染成为可能的api。

You just have to create a dummy dynamic library that simply links against your static library like this: 您只需创建一个虚拟动态库,只需链接您的静态库,如下所示:

https://stackoverflow.com/a/2957386/892714 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. ndk构建系统(遗憾的是)在没有动态库使用的情况下不会创建静态库。 Then you simply grab your static library from obj/local/armeabi-v7a. 然后你只需从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. 你真的不需要任何NDK魔法,因为如果你的项目没有jni/文件夹,如果你把库放在libs/ ,它们就会在那里。 (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 Re:如何构建共享库并在其他ndk程序中调用它
Android NDK - make two native shared libraries calling each other Android NDK - 使两个本机共享库相互调用
Android NDK: Link using a pre-compiled static library Android NDK:使用预编译的静态库链接

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

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