Cocos2d-x & Android & windows7
配置java环境变量
ADT包含了android sdk 和 eclipse;
配置环境变量NDK_ROOT
配置cygwin的环境变量;
LOCAL_SRC_FILES 上加上需要编译的源文件;
LOCAL_WHOLE_STATIC_LIBRARIES 加上需要包含的链接库;
修改cocos2dx相对路径
如:cd /cygdrive/f/cocos2d-2.1rc0-x-2.1.3/samples/Cpp/HelloCpp/proj.android
运行./build_native.sh 编译静态库;
Eclipse > File > Import > Android Project From Existing Code.
选择项目,选择Run As > Android Application
如果编译提示无法识别cocos2d-x,可以Properties > Java Build path > Link Source
选择选择E:\cocos2d-x\cocos2d-2.0-x-2.0.4\cocos2dx\platform\android\java\src路径,Name不与src冲突即可。
注意事项:PC模拟器运行会异常退出,网上搜索说模拟器不支持gles2.0导致的,用真机没有问题。
可以用模拟器启动,勾选使用GPU模拟就行了
Eclipse > Run > Run configurations >
效果图:
Cocos2d-x音效对不同平台实现支持, 编译的时候需要包含对应的路径,
Android下修改makefile文件,如下图:
原来是把源文件一个个列进来,像这样:
LOCAL_SRC_FILES += ../../Classes/class.cpp \
../../Classes/class2.cpp \
../../Classes/class3.cpp \
../../Classes/class4.cpp \
......
又长又繁琐,网上查到一种简易的makefile写法,
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := testandroid_shared LOCAL_MODULE_FILENAME := libtestandroid #目录下所有*.cpp文件; CLASS_FILES := $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp) #目录下任一子目录下所有*.cpp文件; CLASS_FILES += $(wildcard $(LOCAL_PATH)/../../Classes/*/*.cpp) CLASS_FILES := $(CLASS_FILES:$(LOCAL_PATH)/%=%) LOCAL_SRC_FILES := hellocpp/main.cpp LOCAL_SRC_FILES += $(CLASS_FILES) LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes #音频头文件目录; LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../../../CocosDenshion/include LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static include $(BUILD_SHARED_LIBRARY) $(call import-module,cocos2dx) #音频源文件目录; $(call import-module, CocosDenshion/android)
以后不管工程里添加多少源文件,makefile都会全部编译:
#目录下所有*.cpp文件;
CLASS_FILES := $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
#目录下任一子目录下所有*.cpp文件;
CLASS_FILES += $(wildcard $(LOCAL_PATH)/../../Classes/*/*.cpp)
CLASS_FILES := $(CLASS_FILES:$(LOCAL_PATH)/%=%)
LOCAL_SRC_FILES := hellocpp/main.cpp
LOCAL_SRC_FILES += $(CLASS_FILES)
如果是多层子目录,可以这样:
CLASS_FILES += $(wildcard $(LOCAL_PATH)/../../Classes/*/*/*/*.cpp)
*代表任意目录,有几层子目录,就添加几个*号。
参考链接:http://www.cnblogs.com/graphicsme/archive/2012/11/06/2756914.html