1

我正在开发一个应用程序,我在其中使用indic-text-renderer进行 devnagri 文本渲染。因为这是 NDK 库;我正在尝试使用ndk-build命令编译它。但它给了我以下错误:

Android NDK: Trying to define local module 'harfbuzz_ng' in /cygdrive/d/Project_WorkSpace/indic-text-renderer//jni/harfbuzz-ng/Android.mk.
Android NDK: But this module was already defined by /cygdrive/d/Project_WorkSpace/indic-text-renderer//jni/harfbuzz-ng/Android.mk.

我的 android.mk 文件是:

    LOCAL_PATH := $(call my-dir)

MY_LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm

LOCAL_MODULE := complex-script-rendering

LOCAL_C_INCLUDES := $(LOCAL_PATH)/freetype/include $(LOCAL_PATH)/harfbuzz-ng/src

LOCAL_SRC_FILES := complex-script-rendering.c

LOCAL_STATIC_LIBRARIES := ft2 harfbuzz

LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)

include $(MY_LOCAL_PATH)/freetype/Android.mk

include $(MY_LOCAL_PATH)/harfbuzz-ng/Android.mk

JNI 层次结构

我该如何解决这个错误?

我对 NDK 编程很陌生,所以如果这些信息不充分,请告诉我

编辑:

自由类型/Android.mk

ifndef USE_FREETYPE
USE_FREETYPE := 2.4.2
endif

ifeq ($(USE_FREETYPE),2.4.2)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

# compile in ARM mode, since the glyph loader/renderer is a hotspot
# when loading complex pages in the browser
#
LOCAL_ARM_MODE := arm

LOCAL_SRC_FILES:= \
    src/base/ftbbox.c \
    src/base/ftbitmap.c \
    src/base/ftfstype.c \
    src/base/ftglyph.c \
    src/base/ftlcdfil.c \
    src/base/ftstroke.c \
    src/base/fttype1.c \
    src/base/ftxf86.c \
    src/base/ftbase.c \
    src/base/ftsystem.c \
    src/base/ftinit.c \
    src/base/ftgasp.c \
    src/raster/raster.c \
    src/sfnt/sfnt.c \
    src/smooth/smooth.c \
    src/autofit/autofit.c \
    src/truetype/truetype.c \
    src/cff/cff.c \
    src/psnames/psnames.c \
    src/pshinter/pshinter.c

LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/builds \
    $(LOCAL_PATH)/include

LOCAL_CFLAGS += -W -Wall
LOCAL_CFLAGS += -fPIC -DPIC
LOCAL_CFLAGS += "-DDARWIN_NO_CARBON"
LOCAL_CFLAGS += "-DFT2_BUILD_LIBRARY"

# the following is for testing only, and should not be used in final builds
# of the product
#LOCAL_CFLAGS += "-DTT_CONFIG_OPTION_BYTECODE_INTERPRETER"

LOCAL_CFLAGS += -O2

LOCAL_MODULE:= libft2

include $(BUILD_STATIC_LIBRARY)
endif

harfbuzz-ng/android.mk

LOCAL_PATH:= $(call my-dir)

HARFBUZZ_SRC_FILES = \
    src/hb-blob.cc \
    src/hb-buffer-serialize.cc \
    src/hb-buffer.cc \
    src/hb-common.cc \
    src/hb-fallback-shape.cc \
    src/hb-face.cc \
    src/hb-font.cc \
    src/hb-ot-tag.cc \
    src/hb-set.cc \
    src/hb-shape.cc \
    src/hb-shape-plan.cc \
    src/hb-shaper.cc \
    src/hb-tt-font.cc \
    src/hb-unicode.cc \
    src/hb-warning.cc \
    src/hb-ot-layout.cc \
    src/hb-ot-map.cc \
    src/hb-ot-shape.cc \
    src/hb-ot-shape-complex-arabic.cc \
    src/hb-ot-shape-complex-default.cc \
    src/hb-ot-shape-complex-indic.cc \
    src/hb-ot-shape-complex-indic-table.cc \
    src/hb-ot-shape-complex-myanmar.cc \
    src/hb-ot-shape-complex-sea.cc \
    src/hb-ot-shape-complex-thai.cc \
    src/hb-ot-shape-normalize.cc \
    src/hb-ot-shape-fallback.cc

#############################################################
#   build the harfbuzz library
#

include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES:= \
    $(HARFBUZZ_SRC_FILES) \
    src/hb-icu.cc

LOCAL_CPP_EXTENSION := .cc

LOCAL_SHARED_LIBRARIES := \
        libcutils \
        libicuuc \
        libicui18n \
        libutils

LOCAL_C_INCLUDES += \
        $(LOCAL_PATH)/src \
        external/icu4c/common

LOCAL_CFLAGS += -DHB_NO_MT -DHAVE_OT -DHAVE_ICU

LOCAL_LDLIBS += -lpthread

LOCAL_MODULE:= libharfbuzz_ng

include $(BUILD_SHARED_LIBRARY)

#############################################################
#   build the harfbuzz static library
#
include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES:= \
    $(HARFBUZZ_SRC_FILES) \
    src/hb-ucdn.cc \
    src/hb-ucdn/ucdn.c

LOCAL_CPP_EXTENSION     := .cc
LOCAL_STATIC_LIBRARIES  := libft2
LOCAL_C_INCLUDES        := \
  $(LOCAL_PATH)/src \
  external/freetype/include
LOCAL_CFLAGS += -DHB_NO_MT -DHAVE_OT -DHAVE_UCDN -DHAVE_FREETYPE
LOCAL_LDLIBS += -lpthread

LOCAL_MODULE:= libharfbuzz_ng

include $(BUILD_STATIC_LIBRARY)
4

2 回答 2

1

我的 jni/Android.mk 看起来像这样:

LOCAL_PATH := $(call my-dir)

MY_LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm

LOCAL_MODULE := complex-script-rendering

LOCAL_C_INCLUDES := $(LOCAL_PATH)/freetype/include  $(LOCAL_PATH)/harfbuzz-ng/src

LOCAL_SRC_FILES := complex-script-rendering.c

LOCAL_STATIC_LIBRARIES := libfreetype libharfbuzz

LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)
$(call import-module,freetype)

#include $(MY_LOCAL_PATH)/freetype/Android.mk

include $(MY_LOCAL_PATH)/harfbuzz-ng/Android.mk

和 harfbuzz-ng/Android.mk:

LOCAL_PATH:= $(call my-dir)

HARFBUZZ_SRC_FILES = \
    src/hb-blob.cc \
    src/hb-buffer-serialize.cc \
    src/hb-buffer.cc \
    src/hb-common.cc \
    src/hb-fallback-shape.cc \
    src/hb-face.cc \
    src/hb-font.cc \
    src/hb-ot-tag.cc \
    src/hb-ft.cc \
    src/hb-set.cc \
    src/hb-shape.cc \
    src/hb-shape-plan.cc \
    src/hb-shaper.cc \
    src/hb-tt-font.cc \
    src/hb-unicode.cc \
    src/hb-warning.cc \
    src/hb-ot-layout.cc \
    src/hb-ot-map.cc \
    src/hb-ot-shape.cc \
    src/hb-ot-shape-complex-arabic.cc \
    src/hb-ot-shape-complex-default.cc \
    src/hb-ot-shape-complex-indic.cc \
    src/hb-ot-shape-complex-indic-table.cc \
    src/hb-ot-shape-complex-myanmar.cc \
    src/hb-ot-shape-complex-sea.cc \
    src/hb-ot-shape-complex-thai.cc \
    src/hb-ot-shape-normalize.cc \
    src/hb-ot-shape-fallback.cc

#############################################################
#   build the harfbuzz library
#
#
#include $(CLEAR_VARS)
#
#LOCAL_ARM_MODE := arm
#
#LOCAL_MODULE_TAGS := optional
#
#LOCAL_SRC_FILES:= \
#   $(HARFBUZZ_SRC_FILES) \
#   src/hb-icu.cc
#
#LOCAL_CPP_EXTENSION := .cc
#
#LOCAL_SHARED_LIBRARIES := \
#        libcutils \
#        libicuuc \
#        libicui18n \
#        libutils
#
#LOCAL_C_INCLUDES += \
#        $(LOCAL_PATH)/src \
#        external/icu4c/common
#
#LOCAL_CFLAGS += -DHB_NO_MT -DHAVE_OT -DHAVE_ICU
#
#LOCAL_LDLIBS += -lpthread
#
#LOCAL_MODULE:= libharfbuzz_ng
#
#include $(BUILD_SHARED_LIBRARY)

#############################################################
#   build the harfbuzz static library
#
include $(CLEAR_VARS)

LOCAL_ARM_MODE := arm
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES:= \
    $(HARFBUZZ_SRC_FILES) \
    src/hb-ucdn.cc \
    src/hb-ucdn/ucdn.c

LOCAL_CPP_EXTENSION     := .cc
LOCAL_STATIC_LIBRARIES  := libfreetype
LOCAL_C_INCLUDES        := \
  $(LOCAL_PATH)/src \
  $(LOCAL_PATH)/src/hb-ucdn \
  external/freetype/include
LOCAL_CFLAGS += -DHB_NO_MT -DHAVE_OT -DHAVE_UCDN -DHAVE_FREETYPE
LOCAL_LDLIBS += -lpthread

LOCAL_MODULE:= libharfbuzz

include $(BUILD_STATIC_LIBRARY)

我的 jni 目录中有一个 build.sh 文件,它将导出我的 freetype 模块,非常简单:

export NDK_MODULE_PATH=/home/***/workspace/indic-text-renderer/jni

ndk-build

除此之外,您还必须交叉编译 freetype 库。

祝你好运,我花了将近一周的时间。

于 2014-05-15T05:54:54.747 回答
1

我尝试删除整个 BUILD_SHARED_LIBRARY 块,它停止抱怨重新定义问题,因为我想将 harfbuzz-ng 编译为静态库。你可以试一试。

我最后一次遇到这个错误,是当我交叉编译freetype并将它用作我的项目中的预构建静态库时,我导出了NDK-MODULE-PATH,但在我的jni/Android.mk中有一行写include $(MY_LOCAL_PATH)/freetype/Android.mk

所以我只是注释掉这一行,一切正常。

因为当您设置 NDK-MODULE-PATH 时,编译器将查看您的 PATH 目录并搜索 Android.mk 并使用它编译源代码。请参考this,希望对您有所帮助。

于 2014-05-13T10:27:55.383 回答