cocos2d-x 编译成android apk常见错误

1编译CCCommon.cpp

提示信息:

[armeabi] Compile++ thumb: cocos2dx_static <= CCCommon.cpp
D:/cocos2D/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/samples/HelloCpp/proj.android/../../../cocos2dx/platform/android/CCCommon.cpp: In function ‘void cocos2d::CCLog(char const*, ...)‘:
D:/cocos2D/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/samples/HelloCpp/proj.android/../../../cocos2dx/platform/android/CCCommon.cpp:44:72: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus.exe: some warnings being treated as errors

解决方法:在jni/Application.mk后面加

APP_CFLAGS += -Wno-error=format-security

2.没有指向jni/**/main.cpp错误

提示信息:make: *** No rule to make target ‘jni/FX/main.cpp‘, needed by ‘obj/local/armeabi/objs-debug/FX_shared/FX/main.o‘。 停止。

解决方法:jni/Android.mk中的Local_SRC_PATH定义错误,具体的定义方法可以查看cocos2d-x下,自带的sample实例。

3.NDK只支持少量的C或者C++库造成的错误

提示:In file included from jni/FX/main.cpp:1:0:
jni/FX/main.h:7:21: fatal error: windows.h: No such file or directory
compilation terminated.

解决方法:main.cpp书写错误,将main.h去掉

4.main.cpp错误

提示错误信息:[armeabi] Compile++ thumb: FX_shared <= main.cpp
jni/FX/main.cpp:10:14: error: expected initializer before ‘_tWinMain‘

解决方案:按照cocos2d提供的实例去修改main.cpp

5.main.cpp包含了没有的头文件

提示信息:[armeabi] Compile++ thumb: FX_shared <= main.cpp
jni/FX/main.cpp:6:29: fatal error: HelloWorldScene.h: No such file or directory
compilation terminated.

解决方法:去掉没有的头文件

6.Android.mk中的Local_Src_Path定义错误

提示信息:[armeabi] Compile++ thumb: FX_shared <= main.cpp
[armeabi] Compile++ thumb: FX_shared <= *.cpp
arm-linux-androideabi-g++.exe: fatal error: cannot specify -o with -c, -S or -E with multiple files
compilation terminated.

解决方案:按照正确的方法书写Android.mk中的Local_SRC_PATH

7.Box2D/Box2D.h No such file or directory

提示信息:In file included from jni/../../Classes/FX_PauseGameScene.h:2:0,
                 from jni/../../Classes/FX_PauseGameScene.cpp:1:
jni/../../Classes/FX_Global.h:8:25: fatal error: Box2D/Box2D.h: No such file or directory
compilation terminated.
解决方案:将包含的Box2D/Box2D.h头文件去掉。或者将external下的Box2D目录复制到要编译项目的Class文件夹下。或者在Android.mk中增加

LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static

$(call import-module,external/Box2D)

8.SimpleAudioEngine:No such file or directory

提示信息:In file included from jni/../../Classes/FX_PauseGameScene.h:2:0,
                 from jni/../../Classes/FX_PauseGameScene.cpp:1:
jni/../../Classes/FX_Global.h:8:31: fatal error: SimpleAudioEngine.h: No such file or directory
compilation terminated.

解决方案:SimpleAudioEngine.cpp包含在CocosDenshion/android下因此要将加入import-module

LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static

$(call import-module,CocosDenshion/android)
9.build_native.sh中的NDK_BOOT定义格式错误

提示信息:

./build_native.sh: line 32: NDK_ROOT: command not found

定义NDK_ROOT路径是,NDK_ROOT和等号之间没有空格

10.NDK对于C的支持错误

提示信息:[armeabi] Compile++ thumb: FX_shared <= FX_StartGame.cpp
In file included from jni/../../Classes/FX_StartGame.cpp:1:0:
jni/../../Classes/FX_StartGameScene.h:25:2: error: ‘CCArray‘ does not name a type
jni/../../Classes/FX_StartGame.cpp: In member function ‘bool FX_StartGameScene::addPipeSprite()‘:
jni/../../Classes/FX_StartGame.cpp:63:2: error: ‘pAniFrame‘ was not declared in this scope
jni/../../Classes/FX_StartGame.cpp:69:31: error: ‘sprintf_s‘ was not declared in this scope
/cygdrive/D/android-ndk-r9d-windows-x86/android-ndk-r9d/build/core/build-binary.mk:393: recipe for target ‘obj/local/armeabi/objs-debug/FX_sha
make: *** [obj/local/armeabi/objs-debug/FX_shared/__/__/Classes/FX_StartGame.o] Error 1
解决方案:提示有三个错误CCArray does not name a type错误时CCArray没有定义类型,可以将CCArray改为cocos2d::CCArray

sprintf_s was not in this scope

NDK支持特定的C或者C++的库,可以使用sprintf代替sprintf_s

其他常见错误

Q1:[armeabi] Compile++ thumb: FX_shared <= FXSharedMethod.cpp
jni/../../Classes/FXSharedMethod.cpp: In static member function ‘static char* CFXSharedMethod::G2U(char const*)‘:
jni/../../Classes/FXSharedMethod.cpp:15:32: error: ‘CP_ACP‘ was not declared in this scope
jni/../../Classes/FXSharedMethod.cpp:15:62: error: ‘MultiByteToWideChar‘ was not declared in this scope
jni/../../Classes/FXSharedMethod.cpp:19:28: error: ‘CP_UTF8‘ was not declared in this scope
jni/../../Classes/FXSharedMethod.cpp:19:69: error: ‘WideCharToMultiByte‘ was not declared in this scope
/cygdrive/D/android-ndk-r9d-windows-x86/android-ndk-r9d/build/core/build-binary.mk:393: recipe for target ‘obj/local/armeabi/objs-debug/FX_shad
make: *** [obj/local/armeabi/objs-debug/FX_shared/__/__/Classes/FXSharedMethod.o] Error 1
解决方案:使用了不支持的C++库


问题:

创建项目后不能正常运行,提示错误:

fatal error C1083:无法打开包括文件:“CCStdC.h”:No such file or directory

fatal error C1083:无法打开包括文件:“SimpleAudioEngine.h”:No such file or directory

 

解决方法:

 cocos2d-2.0-x-2.0.3中的  cocos2dx   CocosDenshion 文件夹整个复制到工程目录下



cocos2d-x 编译成android apk常见错误,布布扣,bubuko.com

cocos2d-x 编译成android apk常见错误

上一篇:微信支付二维码本地测试可以,上传到服务器不显示问题


下一篇:python爬虫-抓取内涵吧内涵段子