使用cocos2d-x c++ Android静态库

  • Post author:
  • Post category:其他


在用cocos2d-x做Android开发时,每次clean后都会需要再次编译coco2d-x的库,十分耗时。

这里给出一个直接使用静态库而不用每次都编译源码的方法:

1\ 首先找到一个cocos2d-x的测试项目(如cpp_test),进行一次编译。完成后,在proj.android/obj/local目录下可以找到中间过程中生成的所有静态库文件。

把这些静态库文件(带上ABI目录)复制出来,放到一个新的目录(如:cclib)中。

2\ 在cclib中创Android.mk文件,文件内容见代码附1.

3\ 定义环境变量 CC_SRC_ROOT 为cocos2d源码目录(即cocos与external的上层目录)

在编译你的项目时依赖cclib即可,不需要依赖cocos2d目录下的Android.mk

附cclib/Android.mk内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

LOCAL_PATH := $(call my-


dir


)

include $(CLEAR_VARS)

LOCAL_MODULE := cc_static

LOCAL_MODULE_FILENAME := libcc

LOCAL_EXPORT_C_INCLUDES := $(CC_SRC_ROOT)


/cocos


\



$(CC_SRC_ROOT)


/cocos/


. \



$(CC_SRC_ROOT)


/cocos/


.. \



$(CC_SRC_ROOT)


/cocos/platform


\



$(CC_SRC_ROOT)


/cocos/base


\



$(CC_SRC_ROOT)


/external


\



$(CC_SRC_ROOT)


/external/tinyxml2


\



$(CC_SRC_ROOT)


/external/unzip


\



$(CC_SRC_ROOT)


/external/chipmunk/include/chipmunk


\



$(CC_SRC_ROOT)


/external/xxhash


\



$(CC_SRC_ROOT)


/external/nslog


\



$(CC_SRC_ROOT)


/external/poly2tri


\



$(CC_SRC_ROOT)


/external/poly2tri/common


\



$(CC_SRC_ROOT)


/external/poly2tri/sweep


\



$(CC_SRC_ROOT)


/cocos/platform/android


\



$(CC_SRC_ROOT)


/cocos/audio/include


\



$(CC_SRC_ROOT)


/external/curl/include/android


\



$(CC_SRC_ROOT)


/external/websockets/include/android


\



$(CC_SRC_ROOT)


/cocos/editor-support


\



$(CC_SRC_ROOT)


/external/Box2D


\



$(CC_SRC_ROOT)


/external/flatbuffers


\



$(CC_SRC_ROOT)


/external

LOCAL_CFLAGS   :=  -DUSE_FILE32API -fexceptions

LOCAL_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat

LOCAL_EXPORT_CFLAGS   := -DUSE_FILE32API -fexceptions

LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat

LOCAL_EXPORT_LDLIBS := -lGLESv2 \



-llog \



-landroid \



-lGLESv1_CM \



-lEGL \



-lOpenSLES

# define the macro to compile through support/zip_support/ioapi.c

LOCAL_WHOLE_STATIC_LIBRARIES := cocos_freetype2_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_png_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_jpeg_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_tiff_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_webp_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_chipmunk_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_zlib_static

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_curl_static

LOCAL_WHOLE_STATIC_LIBRARIES += websockets_static

LOCAL_WHOLE_STATIC_LIBRARIES += flatbuffers_static

LOCAL_WHOLE_STATIC_LIBRARIES += libaudioengine_static

LOCAL_WHOLE_STATIC_LIBRARIES += libbox2d_static

LOCAL_WHOLE_STATIC_LIBRARIES += libcocos2d_static

LOCAL_WHOLE_STATIC_LIBRARIES += libcocos2dandroid_static

LOCAL_WHOLE_STATIC_LIBRARIES += libcocos2dxinternal_static

LOCAL_WHOLE_STATIC_LIBRARIES += libcocos3d_static

LOCAL_WHOLE_STATIC_LIBRARIES += libcocosbuilder_static

LOCAL_WHOLE_STATIC_LIBRARIES += libcocosdenshion_static

LOCAL_WHOLE_STATIC_LIBRARIES += libcocostudio_static

LOCAL_WHOLE_STATIC_LIBRARIES += libextension_static

LOCAL_WHOLE_STATIC_LIBRARIES += libnetwork_static

LOCAL_WHOLE_STATIC_LIBRARIES += libspine_static

LOCAL_WHOLE_STATIC_LIBRARIES += libui_static

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := flatbuffers_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/flatbuffers


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libaudioengine_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libaudioengine


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libbox2d_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libbox2d


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcocos2d_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcocos2d


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcocos2dandroid_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcocos2dandroid


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcocos2dxinternal_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcocos2dxinternal


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcocos3d_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcocos3d


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcocosbuilder_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcocosbuilder


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcocosdenshion_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcocosdenshion


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcocostudio_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcocostudio


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libcpufeatures_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libcpufeatures


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libextension_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libextension


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libnetwork_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libnetwork


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libspine_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libspine


.a

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := libui_static

LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)


/libui


.a

include $(PREBUILT_STATIC_LIBRARY)

#==============================================================

$(call


import


-module,freetype2


/prebuilt/android


)

$(call


import


-module,png


/prebuilt/android


)

$(call


import


-module,zlib


/prebuilt/android


)

$(call


import


-module,jpeg


/prebuilt/android


)

$(call


import


-module,tiff


/prebuilt/android


)

$(call


import


-module,webp


/prebuilt/android


)

$(call


import


-module,chipmunk


/prebuilt/android


)

$(call


import


-module,curl


/prebuilt/android


)

$(call


import


-module,websockets


/prebuilt/android


)