下面详细介绍一下用NDK r9版本编译cocos2d x 2.0.4可能会遇到的各个坑吧。
错误提示1:
AndroID NDK: WARNING:E:\cocos2d-x\cocos2d-2.0-x-2.0.4/cocos2dx/AndroID.mk:cocos2dx_static: LOCAL_LDliBS is always ignored for static librarIEs
Gdbserver : [arm-linux-androIDeabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
"Compile++ thumb : cocosdenshion_static <= SimpleAudioEngine.cpp
E:\cocos2d-x\cocos2d-2.0-x-2.0.4/CocosDenshion/androID/SimpleAudioEngine.cpp: In constructor 'CocosDenshion::SimpleAudioEngine::SimpleAudioEngine()':
E:\cocos2d-x\cocos2d-2.0-x-2.0.4/CocosDenshion/androID/SimpleAudioEngine.cpp:159:2: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus.exe: some warnings being treated as errors
make: *** [obj/local/armeabI/ObJs-deBUG/cocosdenshion_static/SimpleAudioEngine.o] Error 1
解决方法:把SimpleAudioEngine.cpp第159行注释掉
在文件夹CocosDenshion/androID中找到SimpleAudioEngine.cpp文件,定位到第159行,将其注释掉如下:
//LOGD(deviceModel);
再次用Cygwin Terminal软件运行build_native.sh,又出现新的提示错误。
错误提示2:
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/OpenSLEngine.cpp:292:45: warning: extended initializer Lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/OpenSLEngine.cpp:292:45: warning: extended initializer Lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/OpenSLEngine.cpp: In member function 'voID OpenSLEngine::create Engine(voID*)':
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/OpenSLEngine.cpp:324:3: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus.exe: some warnings being treated as errors
/cygdrive/e/androID-ndk-r9c/build/core/build-binary.mk:388: recipe for target 'obj/local/armeabI/ObJs-deBUG/cocosdenshion_static/opensl/OpenSLEngine.o' Failed
make: *** [obj/local/armeabI/ObJs-deBUG/cocosdenshion_static/opensl/OpenSLEngine.o] Error 1
make: Leaving directory '/cygdrive/e/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID'
错误提示解读:warning我们就不管了,先只看error,OpenSLEngine.cpp文件324行error。
解决方法:把cocos2d-2.0-x-2.0.4\CocosDenshion\androID\opensl文件夹下的OpenSLEngine.cpp文件
324行注释掉 /*LOGD(errorInfo);*/
再次运行build_native.sh,又提示错误。
错误提示3:
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/OpenSLEngine.cpp:292:45: warning: extended initializer Lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/OpenSLEngine.cpp:292:45: warning: extended initializer Lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
[armeabi] Compile++ thumb: cocosdenshion_static <= SimpleAudioEngineOpenSL.cpp
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/SimpleAudioEngineOpenSL.cpp: In member function 'bool SimpleAudioEngineOpenSL::initEngine()':
E:/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID/../../CocosDenshion/androID/opensl/SimpleAudioEngineOpenSL.cpp:41:5: error: format not a string literal and no format arguments [-Werror=format-security]
cc1plus.exe: some warnings being treated as errors
/cygdrive/e/androID-ndk-r9c/build/core/build-binary.mk:388: recipe for target 'obj/local/armeabI/ObJs-deBUG/cocosdens hion_static/opensl/SimpleAudioEngineOpenSL.o' Failed
make: *** [obj/local/armeabI/ObJs-deBUG/cocosdenshion_static/opensl/SimpleAudioEngineOpenSL.o] Error 1
make: Leaving directory '/cygdrive/e/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID'
这次轮到SimpleAudioEngineOpenSL.cpp文件第41行。
解决方法:把cocos2d-2.0-x-2.0.4\CocosDenshion\androID\opensl文件夹下的SimpleAudioEngineOpenSL.cpp文件第41行注释掉:
/*LOGD(errorInfo);*/
再次运行build_native.sh。又提示错误,warning我们就不管了,先只看error。
错误提示4:
/cygdrive/e/androID-ndk-r9c/build/core/build-binary.mk:388: recipe for target 'obj/local/armeabI/ObJs-deBUG/cocos2d x_static/platform/androID/CCCommon.o' Failed
make: *** [obj/local/armeabI/ObJs-deBUG/cocos2dx_static/platform/androID/CCCommon.o] Error 1
make: Leaving directory '/cygdrive/e/cocos2d-2.0-x-2.0.4/cocos2d-2.0-x-2.0.4/testa/proj.androID'
解决方法:这次我们在Application.mk文件后面添加下面代码:
APP_CPPFLAGS += -Wno-error=format-security
再次运行build_native.sh,然后一切就顺利了!我把so文件(libgame.so)在eclipse里面导入androID项目,并编译成apk文件,测试成功。
至此,NDK r9版本就可以用build_native.sh编译成so文件(libgame.so),
已经在真机上测试cocos2d x的hello World成功。
如果再有其他报错应该不是NDK r9本身的原因,建议考虑NDK_ROOT是否设置,或者权限的问题,
或者是项目的代码问题(有一些VC++允许通过的,这里会有细微的差异)。
如果第一次尝试做交叉编译的同学,建议不要用自己写的Classes代码编译,
可以考虑用官方的HelloWorld,这样可以减少困扰。
后来有获取一个更有效的方法:
只需在Application.mk里面添加下面代码: APP_CPPFLAGS+=-Wno-error=format-security 总结以上是内存溢出为你收集整理的用NDK r9版本编译cocos2d x 2.0.4碰到的各个坑全部内容,希望文章能够帮你解决用NDK r9版本编译cocos2d x 2.0.4碰到的各个坑所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)