您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx 3.0打包android遇到的错误(持续更新)

2014-05-31 13:08 417 查看
1.编译时遇到找不到文件的错误:例如fatal error: cocos-ext.h: No such file or directory    ,
fatal error: CocosGUI.h: No such file or directory等。
原因:1,可能android.mk中没有添加相应的cpp文件。2,在xcode下开发,可以直接#include "cocos-ext.h",因为xcode会自动匹配路径,但转到android下,就要加上相应的目录,所以要改成#include "ui/CocosGUI.h"  ,#include "extensions/cocos-ext.h"

2.工程中用到了第三方库libpomelo,正确做法应该是放到cocos2d/external目录下,但是项目因为某种原因没有这么做。所以后面在编写android.mk文件时遇到了一些错误:

Cannot find module with tag 'libpomelo' in import path    
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ? 
然后网上查找解决办法,看到了一篇关于NDK_MODULE_PATH定义问题文章,最后我在项目android.mk文件的末尾加上
$(call import-add-path,/Users/jason/Desktop/1000dreams222/Road2God/libs)    #注释:/Users/jason/Desktop/1000dreams222/Road2God/libs 为libpomelo的绝对路径
$(call import-module,libpomelo)这两句话,搞定。

3.遇到c++语法错误:

error: 'to_string' was not declared in this scope 或者 error: 'to_string' is not a member of 'std'
原因:android上编译不通过,貌似是c++11的bug
解决办法:我写了一个模版函数,如下:
template <typename T>
std::string to_string_platform(T value)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    std::ostringstream os;
    os << value;
    return os.str();
#else
    return std::to_string(value);
#endif
};
在android上使用流操作,其他平台继续使用string的函数。

4.遇到错误:format not a string literal and no format arguments
原因:估计是gcc编译器比较严格,我的gcc编译器是4.2.1,而xcode默认编译器是LLVM 3.0。
解决办法:在application.mk文件中加入下面一句:APP_CPPFLAGS += -Wno-error=format-security

5.今天看别人的代码遇到一个很蛋疼的问题,纠结了我三个多小时。。。(因为俺是c++菜鸟)
上代码:

auto arenabtn =Button::create();
    arenabtn->loadTextures("btn_arena_n.png","btn_arena_o.png",nullptr);
这两句代码看起来没问题吧。。不过在android上就是会崩!看下函数原型 
    void loadTextures(conststd::string& normal,const
std::string& selected, conststd::string& disabled ="", TextureResType texType =
UI_TEX_TYPE_LOCAL);
看到了没,第三个参数是string类型,调用时赋值为nullptr,结果运行时就崩了。所以不要用nullptr,NULL去初始化string类型。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐