cocos2d-x-2.2.3 android 使用已有静态库(*.a),大幅减少编译时间

 cocos2d-x-2.2版本的在这里:http://blog.csdn.net/wk3368/article/details/19995937


升级到了cocos2d-x-2.2.3,之前的prebuild不好使了,重新研究了一下,发现libwebsockets.a已经不需要了,而且有些Andriud.mk文件有变化,于是根据各个静态库对应的Android.mk,重新整理了一份prebuild/Android.mk。下面是完整的流程:


1.假设你是用py生成的项目,projects/YourCpp, Elipse里面,先clean,再Run,大概需要耗时5分钟左右。

2.cocos2d-x-2.2.3/根目录下,新建文件夹prebuild,将projects/YourCpp/proj.android/obj/local/armeabi/下的这5个.a文件拷贝过来:

libbox2d.a
libchipmunk.a
libcocos2d.a
libcocosdenshion.a
libextension.a


然后新建文件Android.mk,内容如下:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dx_static
LOCAL_MODULE_FILENAME := libcocos2d
LOCAL_SRC_FILES := libcocos2d.a
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/../cocos2dx \
$(LOCAL_PATH)/../cocos2dx/include \
$(LOCAL_PATH)/../cocos2dx/kazmath/include \
$(LOCAL_PATH)/../cocos2dx/platform/android \
LOCAL_EXPORT_LDLIBS := -llog \
                       -lz \
                       -lGLESv2
LOCAL_CFLAGS := -Wno-psabi -DUSE_FILE32API
LOCAL_EXPORT_CFLAGS := -Wno-psabi -DUSE_FILE32API
LOCAL_WHOLE_STATIC_LIBRARIES := cocos_libpng_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_jpeg_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libxml2_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libtiff_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_libwebp_static
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := cocosdenshion_static
LOCAL_MODULE_FILENAME := libcocosdenshion
LOCAL_SRC_FILES := libcocosdenshion.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../CocosDenshion/include
LOCAL_CFLAGS += -Wno-psabi
LOCAL_EXPORT_CFLAGS += -Wno-psabi
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := box2d_static
LOCAL_MODULE_FILENAME := libbox2d
LOCAL_SRC_FILES := libbox2d.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../external/Box2D
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := chipmunk_static
LOCAL_MODULE_FILENAME := libchipmunk
LOCAL_SRC_FILES := libchipmunk.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../external/chipmunk/include/chipmunk
LOCAL_CFLAGS := -std=c99
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := cocos_extension_static
LOCAL_MODULE_FILENAME := libextension
LOCAL_SRC_FILES := libextension.a
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/../extensions \
$(LOCAL_PATH)/../extensions/CCBReader \
$(LOCAL_PATH)/../extensions/GUI/CCControlExtension \
$(LOCAL_PATH)/../extensions/GUI/CCScrollView \
$(LOCAL_PATH)/../extensions/network \
$(LOCAL_PATH)/../extensions/LocalStorage \
$(LOCAL_PATH)/../extensions/CocoStudio/Armature
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_curl_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += libwebsockets_static
LOCAL_CFLAGS += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
LOCAL_EXPORT_CFLAGS += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
LOCAL_CPPFLAGS += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
LOCAL_EXPORT_CPPFLAGS += -DCC_ENABLE_CHIPMUNK_INTEGRATION=1
LOCAL_CFLAGS := -fexceptions
include $(PREBUILT_STATIC_LIBRARY)


$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libjpeg)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libpng)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libtiff)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libwebp)

$(call import-module,external/libwebsockets/android)


最终的prebuild目录如下图:


3.修改YourCPP/proj.android/jni/Android.mk,最后几行如下:


4.Eclipse里面,选择项目->clean,然后打开Finder,到projects/YourCpp/proj.android/obj/local/armeabi/里面,把剩下的5个.a删除。

5.Eclipse里面,选择项目->Run,OK

备注:

1.libcpufeatures.a 这个文件,好像每次都是自动生成的,不知道怎么处理。

2.每次Console里面都会有一行WARNING:

Android NDK: WARNING:/Users/xxx/Documents/cocos2d/cocos2d-x-2.2.3/projects/xxx/proj.android/../../../cocos2dx/Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries   

解决办法就是编辑cocos2dx/Android.mk,把155-157行注释掉:

#LOCAL_LDLIBS := -lGLESv2 \
#                -llog \
#                -lz

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值