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類型。
總結
以上是生活随笔為你收集整理的cocos2dx 3.0打包android遇到的错误(持续更新)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: AVFoundation 简介
- 下一篇: 渗透测试python编程之端口扫描
