zoukankan      html  css  js  c++  java
  • cocos2dx 3.0打包android遇到的错误(持续更新)

    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.project中用到了第三方库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类型


  • 相关阅读:
    PHP touch() 函数
    PHP tmpfile() 函数
    PHP tempnam() 函数
    PHP symlink() 函数
    PHP stat() 函数
    pt-table-sync
    P4233 射命丸文的笔记
    C# Task.Run 和 Task.Factory.StartNew 区别
    C# Task.Run 和 Task.Factory.StartNew 区别
    SourceYard 制作源代码包
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/7209897.html
Copyright © 2011-2022 走看看