Cocos2d-x无法构建Android APK

时间:2017-06-24 19:39:52

标签: cocos2d-x cocos2d-x-3.0

我已经创建了一个cocos2d-x(3.14.1和3.15.1)项目,我稍微修改了模板并添加了新的sprite。这在VS中编译很好,应用程序似乎运行。我想构建android apk所以我尝试了这两个命令(api级别android-21和24,也使用android-ndk-r15):

cocos deploy -p android
cocos deploy -p android --android-studio

它似乎开始正确构建,但最终因这些错误而失败:

    D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
constructor 'cocos2d::experimental::AudioDecoder::AudioDecoder(SLEngineItf, cons
t string&, int, int, const FdGetterCallback&)':
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp:108:
73: error: 'malloc' was not declared in this scope
     _pcmData = (char*) malloc(NB_BUFFERS_IN_QUEUE * BUFFER_SIZE_IN_BYTES);
                                                                         ^
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
destructor 'virtual cocos2d::experimental::AudioDecoder::~AudioDecoder()':
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp:126:
18: error: 'free' was not declared in this scope
     free(_pcmData);
                  ^
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
member function 'bool cocos2d::experimental::AudioDecoder::decodeToPcm()':
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp:405:
52: error: 'malloc' was not declared in this scope
         keyInfo = (SLMetadataInfo *) malloc(keySize);
                                                    ^
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp:434:
25: error: 'free' was not declared in this scope
             free(keyInfo);
                         ^
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
member function 'bool cocos2d::experimental::AudioDecoder::resample()':
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp:504:
42: error: 'malloc' was not declared in this scope
     void *outputVAddr = malloc(outputSize);
                                          ^
D:/coco2d/flappybird/RetroBird/cocos2d/cocos/audio/android/AudioDecoder.cpp:594:
17: error: 'free' was not declared in this scope
     free(convert);
                 ^
[armeabi] Compile++ thumb: audioengine_static <= PcmBufferProvider.cpp
make: *** [obj/local/armeabi/objs-debug/audioengine_static/AudioDecoder.o] Error
 1
make: *** Waiting for unfinished jobs....
[armeabi] Compile++ thumb: audioengine_static <= PcmAudioPlayer.cpp
make: Leaving directory `D:/coco2d/flappybird/RetroBird/proj.android-studio/app'

Error running command, return code: 2.

1 个答案:

答案 0 :(得分:0)

您正在使用Android-ndk-r15

将以下内容添加到Android.mk

APP_DEPRECATED_HEADERS := true

看看这个link