注:本文适用于cocos2d-x 3.1使用ant或eclipse编译的方式,其它cocos2d-x版本请注意修改相关引用lib;若用Android Studio,可参考思路,具体实现大为不同。


在用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

!如果修改了cocos2d-x源文件,请重新编译静态库文件。

附cclib/Android.mk内容:

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)

使用cocos2d-x c++ Android静态库的更多相关文章

  1. 在CentOS中编译FFmpeg for Android静态库(含fdk aac,x264)

    本文可以编译出集成了x264和fdk_aac的库,而且支持neon 下载源码: https://github.com/mstorsjo/fdk-aac http://sourceforge.net/p ...

  2. [付费视频]Delphi视频Android开发使用静态库(A)和动态库(SO)

    关于本视频:前阵子接到一个委托,解决Delphi开发Android程序中串口通信的问题,厂家那边提供了c文件,需要翻译成delphi可用,翻译倒是比较简单.不过后来翻译读写ic卡单元的时候进行不下去了 ...

  3. android开发 NDK 编译和使用静态库、动态库 (转)

    在eclipse工程目录下建立一个jni的文件夹 在jni文件夹中建立Android.mk和Application.mk文件 Android.mk文件: Android提供的一种makefile文件, ...

  4. [cocos2dx笔记004] android添加�静态库project

    (基于2.2.2版本号) 这步比較麻烦,不像vs2013那样好设置.參考了非常多文章.还是不能解决这个问题.仅仅有慢慢摸索了.在这里贴出来,希望能让大家能少走点弯路. 还是其于前面的文章提到的myli ...

  5. protobuf使用NDK编译Android的静态库(工作记录)

    1.protobuf 编译过程 前提: 确保自己电脑上已经安装了cygwin + ndk, 并且NDK能够编译hello-jni成功 1.1 把protobuf 压缩包解压到protobuf文件夹下 ...

  6. Android Studio 打包AAR和第三方静态库

    需求 现在有一个第三方库libstatic_add.a和对应的头文件static.h,要求封装一个Module,该Module依赖这个静态库,要求打包的Module包含该静态库. 方案 创建Andro ...

  7. Android导入第三方静态库.a编译成动态库.so

    http://ikinglai.blog.51cto.com/6220785/1324985 在Android开发的时候,经常会使用到用c或c++编写的第三方的静态库.如果有源码的话,可以直接跟你自己 ...

  8. android ndk-build 编译静态库libxx.a 以及Android studio openssl 静态库配置(cmake)

    android ndk-build 编译静态库libxx.a 需求场景: 目前有安卓编码好的现在的openssl的两个.a,我们需要调用openssl的函数,并把功能再封装成.a; 这样使用时,在an ...

  9. Android NDK生成共享库和静态库

    Date: 2014-03-14 Title: Compile Android Native Binary And Library Published: true Type: post Tags: A ...

随机推荐

  1. xshell5激活

    Xshell是一个用于MS Windows平台的强大的SSH,TELNET,和RLOGIN终端仿真软件.它使得用户能轻松和安全地从Windows PC上访问Unix/Linux主机.以上内容全部为广告 ...

  2. ASP.NET连接数据库时,提示“用户 'sa' 登录失败原因: 未与信任 SQL Server 连接相关联

    用ASP.NET连接数据库时,提示"用户 'sa' 登录失败.原因: 未与信任 SQL Server 连接相关联.".解决方法:首先检查是不是web.config文件内的用户名密码 ...

  3. 005_重写 Standard Delete Button

    以后会用JS直接删除,但是在加载.js时候出现问题,会在以后进一步追踪完善: <apex:page standardController="Opportunity" > ...

  4. JavaScript基本数据类型(较易混淆的几个概念)

    1. var a; typeof a;  控制台输出结果是什么? 解答:a只被声明,而未被初始化,在javascript中,未初始化的变量默认值都为undefined; 2. var s=" ...

  5. C#Abstract抽象类的语法

    1. 抽象方法只能放在抽象类中,且不用实现(没有方法体); 2.抽象类中可以放非抽象方法; 3.抽象类不能实例化,只能实例化他的子类,是为子类"活着";

  6. 《利用python进行数据分析》读书笔记--第六章 数据加载、存储与文件格式

    http://www.cnblogs.com/batteryhp/p/5021858.html 输入输出一般分为下面几类:读取文本文件和其他更高效的磁盘存储格式,加载数据库中的数据.利用Web API ...

  7. 理解LSTM网络

    转载自:http://blog.csdn.net/ycheng_sjtu/article/details/48792467

  8. MySql.Data.dll 不支持输出参数

    insert INTO stu(name) VALUES('maimai'); set @ReturnValue=@@IDENTITY; string sql="insert INTO st ...

  9. HQL查询——关联和连接

    HQL查询--关联和连接 为了便于理解有关的使用关联和连接进行HQL查询,首先提供两个具有关联关系的持久化类:Person类和MyEvent类 Person类: import javax.persis ...

  10. LINQ的基本认识

    前些日子,我的一个兄弟问我一个关于LINQ的问题,他问我AsEnumerable()在他写的一大段代码中的作用. 我不太清楚他是知道想考考我,还是不太清楚,想问题一下,反正我不太知道. 以前接触过一些 ...