cairo+svg在Android+cocos2d-x中的编译

svg需要用到libxml2和libiconv库,故需要先编译libxml2和iconv


一:几个注意事项:

  1:注意libxml2的源码下载服务器,不能从git下载,因为不包含configure

  2: libpng和libjpeg头文件需要用cocos2d-x提供的,因为android的cocos2d-x已经包含了这两个库(cocos2d-x用的版本比较低),路径为(需根据实际位置修改)

$(LOCAL_PATH)/../../../../external/cocos2d-x/cocos2dx/platform/third_party/android/prebuilt/libpng/include \

   3:如果报localeconv找不到,请修改为:

#ifndef _ANDROID_
    locale_data = localeconv ();
    decimal_point = locale_data->decimal_point;
#else
    decimal_point = ".";
#endif
一般需要修改 cairo/cairo-output-stream.c, libsvg/svg_ascii.c 文件


二:iconv

  1: 下载源代码:http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

  2:  配置

export NDK_ROOT=/alex_data/tools/android-NDK_ROOT-r8e
export PATH=/alex_data/tools/android-NDK_ROOT-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/darwin-x86_64/bin:$PATH
./configure --host=arm-eabi CC=arm-linux-androideabi-gcc CPPFLAGS="-I$NDK_ROOT/platforms/android-14/arch-arm/usr/include/" CFLAGS="-nostdlib" LDFLAGS="-Wl,-rpath-link=$NDK_ROOT/platforms/android-14/arch-arm/usr/lib/ -L$NDK_ROOT/platforms/android-14/arch-arm/usr/lib/" LIBS="-lc"

  3:在libiconv-1.14添加文件Android.mk

LOCAL_PATH:= $(call my-dir)
LIBICONV_PATH:=$(LOCAL_PATH)
 
include $(CLEAR_VARS)

LOCAL_MODULE := iconv_static

LOCAL_MODULE_FILENAME := libiconv

LOCAL_CFLAGS := \
	-Wno-multichar \
	-D_ANDROID \
	-DLIBDIR=\"\" \
	-DBUILDING_LIBICONV \
	-DIN_LIBRARY
 
LOCAL_C_INCLUDES := \
	$(LIBICONV_PATH)/ \
	$(LIBICONV_PATH)/include \
	$(LIBICONV_PATH)/lib \
	$(LIBICONV_PATH)/libcharset/include
 
LOCAL_SRC_FILES := \
	libcharset/lib/localcharset.c \
	lib/iconv.c \
	lib/relocatable.c
	
include $(BUILD_STATIC_LIBRARY)


二:libxml2

  1:下载源码:ftp://xmlsoft.org/libxml2/libxml2-2.8.0.tar.gz

  (注意,此处不能从git的官网上下载,因为git下载的不包含configure,必须自己配置,此处坑奇多)


  2:配置

  (同iconv,只是需要在libxml2目录下运行)

 3: 在libxml2-2.8.0 添加文件Android.mk

LOCAL_PATH:= $(call my-dir)
LIBXML2_PATH:=$(LOCAL_PATH)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
	c14n.c catalog.c chvalid.c debugXML.c dict.c DOCBparser.c \
	encoding.c entities.c error.c globals.c hash.c HTMLparser.c \
	HTMLtree.c legacy.c list.c nanoftp.c nanohttp.c parser.c \
	parserInternals.c pattern.c relaxng.c SAX.c SAX2.c \
	threads.c tree.c trionan.c triostr.c uri.c valid.c\
	xinclude.c xlink.c xmlIO.c xmlmemory.c xmlmodule.c \
	xmlreader.c xmlregexp.c xmlsave.c xmlschemas.c xmlschemastypes.c xmlstring.c \
	xmlunicode.c xmlwriter.c xpath.c xpointer.c
 
LOCAL_C_INCLUDES := \
	$(LOCAL_PATH)/include \
	$(LOCAL_PATH)/include/libxml \
	$(LIBICONV_PATH)/ \
	$(LIBICONV_PATH)/include \
	$(LIBICONV_PATH)/lib \
	$(LIBICONV_PATH)/libcharset \
	$(LIBICONV_PATH)/libcharset/include
 
LOCAL_CFLAGS := \
	-DHAVA_CONFIG_H
 
LOCAL_LDLIBS := \
	-lz 
 
LOCAL_MODULE:=libxml2

include $(BUILD_STATIC_LIBRARY)

三:cairo Android.mk文件

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := cairo_static

LOCAL_MODULE_FILENAME := libcairo

LOCAL_SRC_FILES := \
	../../Xcode/src/cairo/src/cairo-analysis-surface.c \
	../../Xcode/src/cairo/src/cairo-arc.c \
	../../Xcode/src/cairo/src/cairo-array.c \
	../../Xcode/src/cairo/src/cairo-atomic.c \
	../../Xcode/src/cairo/src/cairo-base64-stream.c \
	../../Xcode/src/cairo/src/cairo-base85-stream.c \
	../../Xcode/src/cairo/src/cairo-bentley-ottmann-rectangular.c \
	../../Xcode/src/cairo/src/cairo-bentley-ottmann-rectilinear.c \
	../../Xcode/src/cairo/src/cairo-bentley-ottmann.c \
	../../Xcode/src/cairo/src/cairo-botor-scan-converter.c \
	../../Xcode/src/cairo/src/cairo-boxes-intersect.c \
	../../Xcode/src/cairo/src/cairo-boxes.c \
	../../Xcode/src/cairo/src/cairo-cache.c \
	../../Xcode/src/cairo/src/cairo-cff-subset.c \
	../../Xcode/src/cairo/src/cairo-clip-boxes.c \
	../../Xcode/src/cairo/src/cairo-clip-polygon.c \
	../../Xcode/src/cairo/src/cairo-clip-region.c \
	../../Xcode/src/cairo/src/cairo-clip-surface.c \
	../../Xcode/src/cairo/src/cairo-clip-tor-scan-converter.c \
	../../Xcode/src/cairo/src/cairo-clip.c \
	../../Xcode/src/cairo/src/cairo-color.c \
	../../Xcode/src/cairo/src/cairo-composite-rectangles.c \
	../../Xcode/src/cairo/src/cairo-compositor.c \
	../../Xcode/src/cairo/src/cairo-contour.c \
	../../Xcode/src/cairo/src/cairo-damage.c \
	../../Xcode/src/cairo/src/cairo-debug.c \
	../../Xcode/src/cairo/src/cairo-default-context.c \
	../../Xcode/src/cairo/src/cairo-deflate-stream.c \
	../../Xcode/src/cairo/src/cairo-device.c \
	../../Xcode/src/cairo/src/cairo-error.c \
	../../Xcode/src/cairo/src/cairo-fallback-compositor.c \
	../../Xcode/src/cairo/src/cairo-fixed.c \
	../../Xcode/src/cairo/src/cairo-font-face-twin-data.c \
	../../Xcode/src/cairo/src/cairo-font-face-twin.c \
	../../Xcode/src/cairo/src/cairo-font-face.c \
	../../Xcode/src/cairo/src/cairo-font-options.c \
	../../Xcode/src/cairo/src/cairo-freed-pool.c \
	../../Xcode/src/cairo/src/cairo-freelist.c \
	../../Xcode/src/cairo/src/cairo-gstate.c \
	../../Xcode/src/cairo/src/cairo-hash.c \
	../../Xcode/src/cairo/src/cairo-hull.c \
	../../Xcode/src/cairo/src/cairo-image-compositor.c \
	../../Xcode/src/cairo/src/cairo-image-info.c \
	../../Xcode/src/cairo/src/cairo-image-source.c \
	../../Xcode/src/cairo/src/cairo-image-surface.c \
	../../Xcode/src/cairo/src/cairo-lzw.c \
	../../Xcode/src/cairo/src/cairo-mask-compositor.c \
	../../Xcode/src/cairo/src/cairo-matrix.c \
	../../Xcode/src/cairo/src/cairo-mesh-pattern-rasterizer.c \
	../../Xcode/src/cairo/src/cairo-misc.c \
	../../Xcode/src/cairo/src/cairo-mono-scan-converter.c \
	../../Xcode/src/cairo/src/cairo-mutex.c \
	../../Xcode/src/cairo/src/cairo-no-compositor.c \
	../../Xcode/src/cairo/src/cairo-observer.c \
	../../Xcode/src/cairo/src/cairo-output-stream.c \
	../../Xcode/src/cairo/src/cairo-paginated-surface.c \
	../../Xcode/src/cairo/src/cairo-path-bounds.c \
	../../Xcode/src/cairo/src/cairo-path-fill.c \
	../../Xcode/src/cairo/src/cairo-path-fixed.c \
	../../Xcode/src/cairo/src/cairo-path-in-fill.c \
	../../Xcode/src/cairo/src/cairo-path-stroke-boxes.c \
	../../Xcode/src/cairo/src/cairo-path-stroke-polygon.c \
	../../Xcode/src/cairo/src/cairo-path-stroke-tristrip.c \
	../../Xcode/src/cairo/src/cairo-path-stroke.c \
	../../Xcode/src/cairo/src/cairo-path.c \
	../../Xcode/src/cairo/src/cairo-pattern.c \
	../../Xcode/src/cairo/src/cairo-pdf-operators.c \
	../../Xcode/src/cairo/src/cairo-pdf-shading.c \
	../../Xcode/src/cairo/src/cairo-pdf-surface.c \
	../../Xcode/src/cairo/src/cairo-pen.c \
	../../Xcode/src/cairo/src/cairo-png.c \
	../../Xcode/src/cairo/src/cairo-polygon-intersect.c \
	../../Xcode/src/cairo/src/cairo-polygon-reduce.c \
	../../Xcode/src/cairo/src/cairo-polygon.c \
	../../Xcode/src/cairo/src/cairo-ps-surface.c \
	../../Xcode/src/cairo/src/cairo-raster-source-pattern.c \
	../../Xcode/src/cairo/src/cairo-recording-surface.c \
	../../Xcode/src/cairo/src/cairo-rectangle.c \
	../../Xcode/src/cairo/src/cairo-rectangular-scan-converter.c \
	../../Xcode/src/cairo/src/cairo-region.c \
	../../Xcode/src/cairo/src/cairo-rtree.c \
	../../Xcode/src/cairo/src/cairo-scaled-font-subsets.c \
	../../Xcode/src/cairo/src/cairo-scaled-font.c \
	../../Xcode/src/cairo/src/cairo-script-surface.c \
	../../Xcode/src/cairo/src/cairo-shape-mask-compositor.c \
	../../Xcode/src/cairo/src/cairo-slope.c \
	../../Xcode/src/cairo/src/cairo-spans-compositor.c \
	../../Xcode/src/cairo/src/cairo-spans.c \
	../../Xcode/src/cairo/src/cairo-spline.c \
	../../Xcode/src/cairo/src/cairo-stroke-dash.c \
	../../Xcode/src/cairo/src/cairo-stroke-style.c \
	../../Xcode/src/cairo/src/cairo-surface-clipper.c \
	../../Xcode/src/cairo/src/cairo-surface-fallback.c \
	../../Xcode/src/cairo/src/cairo-surface-observer.c \
	../../Xcode/src/cairo/src/cairo-surface-offset.c \
	../../Xcode/src/cairo/src/cairo-surface-snapshot.c \
	../../Xcode/src/cairo/src/cairo-surface-subsurface.c \
	../../Xcode/src/cairo/src/cairo-surface-wrapper.c \
	../../Xcode/src/cairo/src/cairo-surface.c \
	../../Xcode/src/cairo/src/cairo-svg-surface.c \
	../../Xcode/src/cairo/src/cairo-time.c \
	../../Xcode/src/cairo/src/cairo-tor-scan-converter.c \
	../../Xcode/src/cairo/src/cairo-tor22-scan-converter.c \
	../../Xcode/src/cairo/src/cairo-toy-font-face.c \
	../../Xcode/src/cairo/src/cairo-traps-compositor.c \
	../../Xcode/src/cairo/src/cairo-traps.c \
	../../Xcode/src/cairo/src/cairo-tristrip.c \
	../../Xcode/src/cairo/src/cairo-truetype-subset.c \
	../../Xcode/src/cairo/src/cairo-type1-fallback.c \
	../../Xcode/src/cairo/src/cairo-type1-glyph-names.c \
	../../Xcode/src/cairo/src/cairo-type1-subset.c \
	../../Xcode/src/cairo/src/cairo-type3-glyph-surface.c \
	../../Xcode/src/cairo/src/cairo-unicode.c \
	../../Xcode/src/cairo/src/cairo-user-font.c \
	../../Xcode/src/cairo/src/cairo-version.c \
	../../Xcode/src/cairo/src/cairo-wideint.c \
	../../Xcode/src/cairo/src/cairo.c

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
						$(LOCAL_PATH)/../../Xcode/src/cairo \
						$(LOCAL_PATH)/../../Xcode/src/cairo/src

LOCAL_C_INCLUDES := $(LOCAL_PATH) \
						$(LOCAL_PATH)/../../Xcode/src/cairo \
						$(LOCAL_PATH)/../../Xcode/src/cairo/src \
						$(LOCAL_PATH)/../../Xcode/src/pixman/pixman \
						$(LOCAL_PATH)/../../../../external/cocos2d-x/cocos2dx/platform/third_party/android/prebuilt/libpng/include

LOCAL_CFLAGS := -DHAVE_CONFIG_H -DPNG_SETJMP_NOT_SUPPORTED -D_ANDROID_

include $(BUILD_STATIC_LIBRARY)

四: libsvg的Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := svg_static

LOCAL_MODULE_FILENAME := libsvg

LOCAL_SRC_FILES := \
	../../Xcode/src/libsvg/src/svg.c \
	../../Xcode/src/libsvg/src/svg_ascii.c \
	../../Xcode/src/libsvg/src/svg_attribute.c \
	../../Xcode/src/libsvg/src/svg_color.c \
	../../Xcode/src/libsvg/src/svg_element.c \
	../../Xcode/src/libsvg/src/svg_gradient.c \
	../../Xcode/src/libsvg/src/svg_group.c \
	../../Xcode/src/libsvg/src/svg_image.c \
	../../Xcode/src/libsvg/src/svg_length.c \
	../../Xcode/src/libsvg/src/svg_paint.c \
	../../Xcode/src/libsvg/src/svg_parser.c \
	../../Xcode/src/libsvg/src/svg_parser_libxml.c \
	../../Xcode/src/libsvg/src/svg_path.c \
	../../Xcode/src/libsvg/src/svg_pattern.c \
	../../Xcode/src/libsvg/src/svg_str.c \
	../../Xcode/src/libsvg/src/svg_style.c \
	../../Xcode/src/libsvg/src/svg_text.c \
	../../Xcode/src/libsvg/src/svg_transform.c

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
						$(LOCAL_PATH)/../../Xcode/src/libsvg

LOCAL_C_INCLUDES := $(LOCAL_PATH) \
						$(LOCAL_PATH)/../../Xcode/src/libsvg/src \
						$(LOCAL_PATH)/../../../../external/cocos2d-x/cocos2dx/platform/third_party/android/prebuilt/libpng/include \
						$(LOCAL_PATH)/../../../../external/cocos2d-x/cocos2dx/platform/third_party/android/prebuilt/libjpeg/include \
						$(LOCAL_PATH)/../libxml2-2.8.0/include \
						$(LOCAL_PATH)/../libiconv-1.14/include

LOCAL_CFLAGS := -DHAVE_CONFIG_H -D_ANDROID_

include $(BUILD_STATIC_LIBRARY)

五:libsvg-cairo

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := svg_cairo_static

LOCAL_MODULE_FILENAME := libsvg_cairo

LOCAL_SRC_FILES := \
	../../Xcode/src/libsvg-cairo/src/svg_cairo.c \
	../../Xcode/src/libsvg-cairo/src/svg_cairo_sprintf_alloc.c \
	../../Xcode/src/libsvg-cairo/src/svg_cairo_state.c

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)

LOCAL_C_INCLUDES := $(LOCAL_PATH) \
						$(LOCAL_PATH)/../../Xcode/src/libsvg/src \
						$(LOCAL_PATH)/../../Xcode/src/cairo/src \
						$(LOCAL_PATH)/../libxml2-2.8.0/include

include $(BUILD_STATIC_LIBRARY)

六:pixman

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := pixman_static

LOCAL_MODULE_FILENAME := libpixman

LOCAL_SRC_FILES := \
	../../../../external/pixman/pixman/pixman-access-accessors.c \
	../../../../external/pixman/pixman/pixman-access.c \
	../../../../external/pixman/pixman/pixman-bits-image.c \
	../../../../external/pixman/pixman/pixman-combine32.c \
	../../../../external/pixman/pixman/pixman-combine64.c \
	../../../../external/pixman/pixman/pixman-conical-gradient.c \
	../../../../external/pixman/pixman/pixman-cpu.c \
	../../../../external/pixman/pixman/pixman-edge-accessors.c \
	../../../../external/pixman/pixman/pixman-edge.c \
	../../../../external/pixman/pixman/pixman-fast-path.c \
	../../../../external/pixman/pixman/pixman-general.c \
	../../../../external/pixman/pixman/pixman-gradient-walker.c \
	../../../../external/pixman/pixman/pixman-image.c \
	../../../../external/pixman/pixman/pixman-implementation.c \
	../../../../external/pixman/pixman/pixman-linear-gradient.c \
	../../../../external/pixman/pixman/pixman-matrix.c \
	../../../../external/pixman/pixman/pixman-noop.c \
	../../../../external/pixman/pixman/pixman-radial-gradient.c \
	../../../../external/pixman/pixman/pixman-region16.c \
	../../../../external/pixman/pixman/pixman-region32.c \
	../../../../external/pixman/pixman/pixman-solid-fill.c \
	../../../../external/pixman/pixman/pixman-timer.c \
	../../../../external/pixman/pixman/pixman-trap.c \
	../../../../external/pixman/pixman/pixman-utils.c \
	../../../../external/pixman/pixman/pixman.c

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
						$(LOCAL_PATH)/../../../../external/pixman/pixman

LOCAL_C_INCLUDES := $(LOCAL_PATH) \
						$(LOCAL_PATH)/../../../../external/pixman/pixman

LOCAL_CFLAGS := -DHAVE_CONFIG_H

include $(BUILD_STATIC_LIBRARY)


七:上一层Android.mk文件需添加

LOCAL_WHOLE_STATIC_LIBRARIES := cairo_static pixman_static svg_static svg_cairo_static iconv libxml2 

include $(BUILD_STATIC_LIBRARY)

$(call import-module,cocos2dx/android/pixman)
$(call import-module,cocos2dx/android/cairo)

$(call import-module,cocos2dx/android/libiconv-1.14)
$(call import-module,cocos2dx/android/libxml2-2.8.0)
$(call import-module,cocos2dx/android/libsvg)
$(call import-module,cocos2dx/android/libsvg-cairo)



你可能感兴趣的:(cairo+svg在Android+cocos2d-x中的编译)