我正在尝试为Android编译libharu。在我的 jni 文件夹中我已经:
这是我的 Android.mk (在 / jni / 文件夹中)。 libharu与libpng有依赖关系所以我先编译libpng。
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
sources := png.c \
pngerror.c \
pngget.c \
pngmem.c \
pngpread.c \
pngread.c \
pngrio.c \
pngrtran.c \
pngrutil.c \
pngset.c \
pngtrans.c \
pngwio.c \
pngwrite.c \
pngwtran.c \
pngwutil.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/lpng154
LOCAL_MODULE := png
LOCAL_LDLIBS := -lz
LOCAL_SRC_FILES := $(sources:%=lpng154/%)
include $(BUILD_STATIC_LIBRARY)
然后编译libharu。
include $(CLEAR_VARS)
sources := hpdf_annotation.c \
hpdf_array.c \
hpdf_binary.c \
hpdf_boolean.c \
hpdf_catalog.c \
hpdf_destination.c \
hpdf_dict.c \
hpdf_doc.c \
hpdf_doc_png.c \
hpdf_encoder.c \
hpdf_encoder_cns.c \
hpdf_encoder_cnt.c \
hpdf_encoder_jp.c \
hpdf_encoder_kr.c \
hpdf_encrypt.c \
hpdf_encryptdict.c \
hpdf_error.c \
hpdf_ext_gstate.c \
hpdf_font.c \
hpdf_font_cid.c \
hpdf_fontdef_base14.c \
hpdf_fontdef.c \
hpdf_fontdef_cid.c \
hpdf_fontdef_cns.c \
hpdf_fontdef_cnt.c \
hpdf_fontdef_jp.c \
hpdf_fontdef_kr.c \
hpdf_fontdef_tt.c \
hpdf_fontdef_type1.c \
hpdf_font_tt.c \
hpdf_font_type1.c \
hpdf_gstate.c \
hpdf_image.c \
hpdf_image_png.c \
hpdf_info.c \
hpdf_list.c \
hpdf_mmgr.c \
hpdf_name.c \
hpdf_namedict.c \
hpdf_null.c \
hpdf_number.c \
hpdf_objects.c \
hpdf_outline.c \
hpdf_page_label.c \
hpdf_page_operator.c \
hpdf_pages.c \
hpdf_real.c \
hpdf_streams.c \
hpdf_string.c \
hpdf_u3d.c \
hpdf_utils.c \
hpdf_xref.c \
hpdf_pdfa.c
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/lpng154 \
$(LOCAL_PATH)/libharu-2.2.1/include \
$(LOCAL_PATH)/libharu-2.2.1/src
LOCAL_LDLIBS := -lz -lm
LOCAL_MODULE := haru
LOCAL_SRC_FILES := $(sources:%=libharu-2.2.1/src/%)
LOCAL_STATIC_LIBRARIES := z png
include $(BUILD_SHARED_LIBRARY)
当我运行 ndk-buid 时,编译器在尝试编译文件时停止* hpdf_image_png.c *,其中包含许多错误:
.../src/hpdf_image_png.c: In function 'ReadPngData_Interlaced':
.../src/hpdf_image_png.c:113: error: dereferencing pointer to incomplete type
.../src/hpdf_image_png.c:118: error: dereferencing pointer to incomplete type
.../src/hpdf_image_png.c:119: error: dereferencing pointer to incomplete type
.../src/hpdf_image_png.c:129: error: dereferencing pointer to incomplete type
...
...
我猜ndk-build找不到 png.h ...我怎么能帮助编译器找到标题?
如果在我的Android.mk中添加了标记:
LOCAL_CFLAGS := -DLIBHPDF_HAVE_NOPNGLIB
在两行之前:
LOCAL_LDLIBS := -lz -lm
LOCAL_MODULE := haru
...
并运行 ndk-build ,编译正常......但我会错过libharu中的png嵌入。
感谢你们所有人。
答案 0 :(得分:1)
使用libpng 1.5进行编译时,libharu中存在一个错误。
您可以应用此补丁: https://github.com/tony2001/libharu/commit/e5bf8b01f6c3d5e3fe0e26ac5345e0da10c03934
答案 1 :(得分:1)
因为您错过了文件“pnglibconf.h”,您可以在lpng / scripts / pnglibconf.h.prebuilt中找到它, 只需将pnglibconf.h.prebuilt重命名为pnglibconf.h,然后添加到文件夹lpng。 你还需要修改文件:hpdf_image_png.c,在#include png.h之后添加以下行:#include pnginfo.h。 就是这样,我相信你能成功。
答案 2 :(得分:0)
我使用了jimtoner的答案。 几乎是对的。但在我的情况下(lpng 1.6.3),我还需要修改文件:hpdf_image_png.c,在#include之后添加#include。 它成功了!