修改cocos2d-x 3.3 androID mk文件 为 自动遍历*.cpp文件,亲测~~
我们在自己新建的项目中,比如项目Mycpp,在项目Mycpp\proj.androID\jni的路径下找到androID mk 文件,先来看看这个androID.mk文件的内容,打开之后是这样子的,我们没有改过
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)LOCAL_MODulE := cocos2dcpp_sharedLOCAL_MODulE_filename := libcocos2dcppLOCAL_SRC_fileS := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cppLOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ClassesLOCAL_WHolE_STATIC_liBRARIES := cocos2dx_staticLOCAL_WHolE_STATIC_liBRARIES += cocosdenshion_static# LOCAL_WHolE_STATIC_liBRARIES += Box2d_static# LOCAL_WHolE_STATIC_liBRARIES += cocosbuilder_static# LOCAL_WHolE_STATIC_liBRARIES += spine_static# LOCAL_WHolE_STATIC_liBRARIES += cocostudio_static # 添加 cocostudio 静态库# LOCAL_WHolE_STATIC_liBRARIES += cocos_network_static# LOCAL_WHolE_STATIC_liBRARIES += cocos_extension_static # 添加 cocos_extension 静态库include $(BUILD_SHARED_liBRARY)$(call import-module,.)$(call import-module,audio/androID)# $(call import-module,Box2D)# $(call import-module,editor-support/cocosbuilder)# $(call import-module,editor-support/spine)# $(call import-module,editor-support/cocostudio) # 导入 cocostudio 模块 # $(call import-module,network)# $(call import-module,extensions) # 导入 extensions 模块
上面这段代码就是新建项目之后,原装的代码 其中 “#” 是注释
如果我们在自己的cpp项目中有用到这两个库的话,cocostudio,extensions,只需要去掉androID.mk文件中的注释号“#”,虽然cocos2dx 的团队已经提醒了我们,只不过在前面加了“#”注释号,就是上面有注释的几行代码,不过还是需要注意的是,如果在cpp项目中要添加头文件的话,需要这样子写,
#include "extensions/cocos-ext.h"#include "cocostudio/CocoStudio.h
这样在编译androID项目的时候,才不会报错
如果写成下面这个的话,win32环境下虽然能编译通过,但是在androID环境下是编译不通过的,要注意
#include "cocos-ext.h"#include "CocoStudio.h
LOCAL_SRC_fileS := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp
改为:
# 遍历目录及子目录的函数 define walk $(wildcard $(1)) $(foreach e,$(wildcard $(1)/*),$(call walk,$(e))) endef # 遍历Classes目录 ALLfileS = $(call walk,$(LOCAL_PATH)/../../Classes) file_List := hellocpp/main.cpp # 从所有文件中提取出所有.cpp文件 file_List += $(filter %.cpp,$(ALLfileS)) LOCAL_SRC_fileS := $(file_List:$(LOCAL_PATH)/%=%)
其他部分不变。然后就可以了。。
改完之后完整androID mk 文件如下:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)LOCAL_MODulE := cocos2dcpp_sharedLOCAL_MODulE_filename := libcocos2dcpp# 遍历目录及子目录的函数 define walk $(wildcard $(1)) $(foreach e,$(ALLfileS)) LOCAL_SRC_fileS := $(file_List:$(LOCAL_PATH)/%=%)LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ClassesLOCAL_WHolE_STATIC_liBRARIES := cocos2dx_staticLOCAL_WHolE_STATIC_liBRARIES += cocosdenshion_staticLOCAL_WHolE_STATIC_liBRARIES += Box2d_staticLOCAL_WHolE_STATIC_liBRARIES += cocosbuilder_staticLOCAL_WHolE_STATIC_liBRARIES += spine_staticLOCAL_WHolE_STATIC_liBRARIES += cocostudio_static # 添加 cocostudio 静态库LOCAL_WHolE_STATIC_liBRARIES += cocos_network_staticLOCAL_WHolE_STATIC_liBRARIES += cocos_extension_static # 添加 cocos_extension 静态库include $(BUILD_SHARED_liBRARY)$(call import-module,audio/androID)$(call import-module,Box2D)$(call import-module,editor-support/cocosbuilder)$(call import-module,editor-support/spine)$(call import-module,editor-support/cocostudio) # 导入 cocostudio 模块$(call import-module,network)$(call import-module,extensions) # 导入 extensions 模块
然后就可以编译通过了。。
AndroID.mk文件
基本语法:
“#” 注释
“:=” 赋值
“+=” 追加
“$” 引用某变量的值
#宏函数my-dir返回编译系统提供的当前路径,即AndroID.mk的目录#如(HelloWorld/proj.androID/jni/XX)LOCAL_PATH := $(call my-dir)#初始化模块 重置除LOCAL_PATH变量以外的所有变量 include $(CLEAR_VARS)#导入库目录$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)#模块名,唯一。LOCAL_MODulE := cocos2dcpp_shared#模块文件名,唯一(可选)LOCAL_MODulE_filename := libcocos2dcpp#配置头文件的搜索范围LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes#获取静态库LOCAL_WHolE_STATIC_liBRARIES := cocos2dx_static#追加静态库LOCAL_WHolE_STATIC_liBRARIES += cocosdenshion_static#根据编译器提供的变量BUILD_SHARED_liBRARY生成动态库include $(BUILD_SHARED_liBRARY)#导入模块,以下是常用的几个模块$(call import-module,audio/androID)$(call import-module,editor-support/cocostudio)$(call import-module,extensions)总结
以上是内存溢出为你收集整理的cocos2d-x 3.3 android mk文件 之 自动遍历*.cpp文件全部内容,希望文章能够帮你解决cocos2d-x 3.3 android mk文件 之 自动遍历*.cpp文件所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)