我正在开发一个应用程序,我在其中使用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
如何解决此错误?
我对NDK编程很新,所以如果这些信息不充分,请告诉我
修改
freetype的/ 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-纳克/ 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)
答案 0 :(得分:1)
我尝试删除整个BUILD_SHARED_LIBRARY块并停止抱怨重新定义问题,因为我想将harfbuzz-ng编译为静态库。你可以尝试一下。
我最后一次收到此错误,就是当我交叉编译freetype并在项目中将其用作PRE构建的静态库时,我导出了NDK-MODULE-PATH但是我的jni中还有一行代码/Android.mk写了include $(MY_LOCAL_PATH)/freetype/Android.mk
所以我只是注释掉这一行,一切正常。
因为当您设置NDK-MODULE-PATH时,编译器将查看您的PATH目录并搜索Android.mk并使用它编译源代码。请参考this,我希望它会对您有所帮助。
答案 1 :(得分: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库。
祝你好运,我花了将近一个星期。