cocos2d-x ndk使用已有静态库,减少编译时间

cocos2d-x做android native编译的时候,总是每次重新编译cocos2dx部份,这个时间伤不起啊。

在网上找到了一个参考http://vaero.blog.51cto.com/4350852/1117957,感谢原作者。

我在他的基础上,根据自己的理解,做了一些修改。


我做的测试是基于cocos2d-2.1beta3-x-2.1.1进行的。

游戏名称为Test,直接放在cocos2d-2.1beta3-x-2.1.1根目录下。

1)进入Test/proj.android执行一次build_native.sh

目的是生成要使用的cocos2dx的各种静态库,会在Test/proj.android/obj/local/armeabi找到各种*.a文件。


2)在cocos2d-2.1beta3-x-2.1.1根目录下,新建prebuild文件夹,拷贝第一部份生成的所有*.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

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
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
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_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_curl_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
include $(PREBUILT_STATIC_LIBRARY)



$(call import-module,libjpeg)
$(call import-module,libpng)
$(call import-module,libxml2)
$(call import-module,libtiff)
$(call import-module,libcurl)



Android.mk拷贝到这后,\后面被加了空格,编译会出错,把我的原文件粘在这
http://download.csdn.net/detail/etring/5086508


3)修改Test/proj.android/jni目录下的Android.mk,如:

#$(call import-module,external/Box2D)
#$(call import-module,external/chipmunk)
#$(call import-module,CocosDenshion/android) \
#$(call import-module,cocos2dx) \
#$(call import-module,extensions)
$(call import-module,prebuild)

也就是注释掉原有的call import-module,新加一个prebuild


执行build_native.sh,搞定。

这样第一次编译coco2dx,后面都可以直接使用,大大节省时间。




评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值