• Mac上利用Eclipse编译Cocos2d-x


    目前使用较多的Cocos2d-x开发平台是XCode,应该是由于大部分Cocos2d-x开发者都是iOS开发出生。但是当我们将XCode开发的Cocos2d-x工程发布Android版本时,每次都需要使用ndk将Cocos2d-x的C++代码编译一遍,然后再用Eclipse打开,这个过程比较麻烦。于是本人尝试在Eclipse中实时编译Cocos2d-x的工程,即可以随时修改或添加java和android代码后,点击Eclipse中的运行完成编译。

    参考的编译Cocos2d-x的教程如下:

    http://www.xuephp.com/main/detail.php?cid=32787

    按以上的教程配置完成后,运行,依然会出现一些错误,如下:

    错误1

    make: *** [clean-box2d_static-armeabi] Error 2

    这是ndkr8e的一个bug

    解决方案

    修改android-ndk-r8e/build/core/build-binary.mk

    $(cleantarget): PRIVATE_CLEAN_FILES := ($(my)OBJS)

    为:

    $(cleantarget): PRIVATE_CLEAN_FILES := $($(my)OBJS


    错误2

    Type Symbol 'cocos2d' could not be resolved

    没有引入Cocos2d-x的源文件

    解决方案

    1.right click project, and select PropertiesC/C++ GeneralPaths and SymbolsSource location. Click Link Folder, check the Link to a folder in the file system checkbox, and browse to the cocos2dxdirectory inside the $COCOS2DX_HOME folder.( the same way as add Classes)

    2.right click project and select PropertiesC/C++ GeneralPath and SymbolsGNU C++. Add$(COCOS2DX_HOME)/CocosDenshion/include


    错误3

    Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml

    最小SDK版本错误

    解决方案

    将AndroidManifest.xml文件中的android:minSdkVersion改为14


    解决以上错误后,以后修改Java或C++代码直接在Eclipse中运行即可。但是当我们在Eclipse中创建新的C++类仍然会报错。因为还需要在工程中的Android.mk文件中添加相应的C++类名。但是每次添加类都要修改Android.mk会比较麻烦。在这里提一个解决方案,可以将Android.mk中的文件改成*.cpp的形式,例如:

     

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    LOCAL_MODULE := game_shared
    
    LOCAL_MODULE_FILENAME := libgame
    
    FILE_LIST := $(wildcard $(LOCAL_PATH)/../../Classes/Actions/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Constants/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Helpers/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/GameObjects/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Scenes/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/Singletons/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/JNICalls/*.cpp)
    FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
    
    LOCAL_SRC_FILES := helloworld/main.cpp
    
    LOCAL_SRC_FILES += $(FILE_LIST:$(LOCAL_PATH)/%=%)
    
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
    
    LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static
    
    include $(BUILD_SHARED_LIBRARY)
    
    $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)
    

    完成以上步骤,即可实现在Eclipse中实时编译Cocos2d-x的工程。

  • 相关阅读:
    C++ 类
    百练3383:Cell Phone Network
    百练4092:牛仔裤
    百练4091:最近餐馆
    百练4090:超级备忘录
    百练2868:牛顿迭代
    百练2812:恼人的青蛙
    百练2805:正方形
    bzoj1856 [Scoi2010]字符串
    bzoj2096 [Poi2010]Pilots
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3194321.html
Copyright © 2020-2023  润新知