注:本文适用于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静态库的更多相关文章
-
在CentOS中编译FFmpeg for Android静态库(含fdk aac,x264)
本文可以编译出集成了x264和fdk_aac的库,而且支持neon 下载源码: https://github.com/mstorsjo/fdk-aac http://sourceforge.net/p ...
-
[付费视频]Delphi视频Android开发使用静态库(A)和动态库(SO)
关于本视频:前阵子接到一个委托,解决Delphi开发Android程序中串口通信的问题,厂家那边提供了c文件,需要翻译成delphi可用,翻译倒是比较简单.不过后来翻译读写ic卡单元的时候进行不下去了 ...
-
android开发 NDK 编译和使用静态库、动态库 (转)
在eclipse工程目录下建立一个jni的文件夹 在jni文件夹中建立Android.mk和Application.mk文件 Android.mk文件: Android提供的一种makefile文件, ...
-
[cocos2dx笔记004] android添加�静态库project
(基于2.2.2版本号) 这步比較麻烦,不像vs2013那样好设置.參考了非常多文章.还是不能解决这个问题.仅仅有慢慢摸索了.在这里贴出来,希望能让大家能少走点弯路. 还是其于前面的文章提到的myli ...
-
protobuf使用NDK编译Android的静态库(工作记录)
1.protobuf 编译过程 前提: 确保自己电脑上已经安装了cygwin + ndk, 并且NDK能够编译hello-jni成功 1.1 把protobuf 压缩包解压到protobuf文件夹下 ...
-
Android Studio 打包AAR和第三方静态库
需求 现在有一个第三方库libstatic_add.a和对应的头文件static.h,要求封装一个Module,该Module依赖这个静态库,要求打包的Module包含该静态库. 方案 创建Andro ...
-
Android导入第三方静态库.a编译成动态库.so
http://ikinglai.blog.51cto.com/6220785/1324985 在Android开发的时候,经常会使用到用c或c++编写的第三方的静态库.如果有源码的话,可以直接跟你自己 ...
-
android ndk-build 编译静态库libxx.a 以及Android studio openssl 静态库配置(cmake)
android ndk-build 编译静态库libxx.a 需求场景: 目前有安卓编码好的现在的openssl的两个.a,我们需要调用openssl的函数,并把功能再封装成.a; 这样使用时,在an ...
-
Android NDK生成共享库和静态库
Date: 2014-03-14 Title: Compile Android Native Binary And Library Published: true Type: post Tags: A ...
随机推荐
-
实例介绍Cocos2d-x物理引擎:碰撞检测
碰撞检测是使用物理引擎的一个重要目的,使用物理引擎可以进行精确的碰撞检测,而且执行的效率也很高.在Cocos2d-x 3.x中使用事件派发机制管理碰撞事件,EventListenerPhysicsCo ...
-
一次服务器CPU占用率高的定位分析
现象: 当前项目启动一段时间,有一个服务导致CPU使用率持续超过30% 环境:Windows 7, CPU: 8核, 内存: 8g内存 定位过程: 启动项目,查看Java进程ID 查看Event P ...
-
Jquery案例——某网站品牌列表的效果
一下是效果图.点击"显示全部品牌",高亮推荐品牌,并显示全部品牌. HTML文件: <!DOCTYPE html> <html lang="en&quo ...
-
Host myCloudData.net on your own server (支持自建服务器)
http://www.myclouddata.net/#/home Host myCloudData.net on your own serverUse the myCloudData.net SDK ...
-
获取Excel表中各个Sheet的方法
获取Excel表中各个Sheet的方法 private void simpleButton2_Click(object sender, EventArgs e) { OfdBOM.Filter = & ...
-
Quick Sort(Java)
public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextI ...
-
Docker 容器CPU设置
CPU使用率其实就是你运行的程序占用的CPU资源,表示你的机器在某个时间点的运行程序的情况.使用率越高,说明你的机器在这个时间上运行了很多程序,反之较少.CPU使用率的高低与你的CPU强弱有直接关系. ...
-
How to Train Triplet Networks with 100K Identities?
1. 为什么介绍此文? Triplet net 改进工作之一,主要思想是在大数据集(人脸识别)上的困难样本挖掘.人脸识别工作对于图像对匹配而言很有借鉴意义,共性是特征的提取和样本数据的挖掘. Trip ...
-
Windows平台上使用Github搭建Git服务器的图文教程
Git没有客户端服务器端的概念,但是要共享Git仓库,就需要用到通信协议,例如SSH协议(FTP , HTTPS , SFTP等协议也能实现Git共享,此文档不讨论),但是SSH有客户端服务器端,所以 ...
-
AngularJS实战之filter的使用一
一.格式化数字为货币格式. <div>{{money|currency:"$"}}</div> <div>{{money|currency:&q ...