cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.29k stars 7.06k forks source link

Android fails to deploy APK on new project #17981

Open defunky opened 7 years ago

defunky commented 7 years ago

Steps to Reproduce:

  1. Create a new project using the following command: cocos new GameNameHere -p com.MyCompany.GameNameHere -l cpp -d pathtoproject
  2. Opening win32 project and building works fine and will run default application
  3. Try and build an android APK using the following command: cocos deploy -p android or cocos deploy -p android --android-studio
  4. It will begin to build and half way it will error out with this message:
D:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
constructor 'cocos2d::experimental::AudioDecoder::AudioDecoder(SLEngineItf, cons
t string&, int, int, const FdGetterCallback&)':
D:/YourGame/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:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
destructor 'virtual cocos2d::experimental::AudioDecoder::~AudioDecoder()':
D:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp:126:
18: error: 'free' was not declared in this scope
     free(_pcmData);
                  ^
D:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
member function 'bool cocos2d::experimental::AudioDecoder::decodeToPcm()':
D:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp:405:
52: error: 'malloc' was not declared in this scope
         keyInfo = (SLMetadataInfo *) malloc(keySize);
                                                    ^
D:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp:434:
25: error: 'free' was not declared in this scope
             free(keyInfo);
                         ^
D:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp: In
member function 'bool cocos2d::experimental::AudioDecoder::resample()':
D:/YourGame/cocos2d/cocos/audio/android/AudioDecoder.cpp:504:
42: error: 'malloc' was not declared in this scope
     void *outputVAddr = malloc(outputSize);
                                          ^
D:/YourGame/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:/YourGame/proj.android-studio/app'

Error running command, return code: 2.
defunky commented 7 years ago

any ideas??

minggo commented 7 years ago

May be you should try this PR: https://github.com/cocos2d/cocos2d-x/pull/17943

orionnoir commented 7 years ago

I have this same exact issue on Android, using mac os. I have rolled the tools folder back to get around the android utility being missing (downgraded to r25.2.5.) But this is a new install of the Android SDK otherwise.

I've tried the APP_DEPRECATED_HEADERS := true in the android mk files to no avail. https://android.googlesource.com/platform/ndk/+/ndk-r15-release/docs/UnifiedHeaders.md

But everything was installed on this new machine as of a few days ago. What I can't find is specifics on what ndk version to use, android sdk (clearly the tools version changed). The last instructions (programmers guide) were written/updated two years ago.

Where is the best place to get these instructions? What is the last tested tool configurations? I am almost certain this is a case of Android SDK, Android NDK, and the Android Studio tools changing faster than Cocos2d-x can keep up in regards to stability and deprecating their features rendering cocos2d-x defunct. Taking note of the last tested system configurations would be very helpful in this situation. Please advise.

**Edit: I should add that cpp-tests compiled successfully without error.

minggo commented 7 years ago

@orionnoir yep, since v3.16, we will ask QA team to use the same environment to test. And we will provide this information in README.

orionnoir commented 7 years ago

Thank you. Has there been any more developments? I just saw the announcement for 3.16. I am rolling back NDK/SDK/IDE versions to find a combo that works so we can proceed. Is there another resource we can tap on this to get the min/max requirements? I am looking at the 3.15.1 readme and starting with the following guidance:

NDK r11+ is required to build Android games Android Studio 2.3+ to build Android games

If I understand you correctly starting with 3.16 the readme will also be including the top end 'tested' versions instead of just the minimums?

minggo commented 7 years ago

In previous we just min/max for to require NDK and Android Studio version. But we can not test all versions. What i mean is that, the QA team will only test on version of NDK and one version of Android Studio, other versions may work, but we can not make sure.

orionnoir commented 7 years ago

I think I know what caused the confusion (if proven to be true...) It was not clear to me what the '+' meant (I now think it means the 'minor' version value. e.g., 'r11a' or 'r11b' for the NDK to use. I indeed am looking for the exact tested android ide/tool versions for 3.15.1 at its release. I am reading between the lines that specifically NDK r11[a-z] (and NDK r11+ was not meant to mean r12 or r13, etc.) is required to build Android games and Android Studio 2.3[.#] (and not 3.x or 2.4.x, etc.)

Grabbing latest from Google for all the tools was a complete waste of time (since I was limiting myself to the officially distributed/supported Android tools.

If what I surmise is a true statement I will test and report back. Looking for the listed NDK(s) now. Someone has got to have these cached somewhere, the internet is forever. In the future I'd like to know exactly what versions of tools (e.g. NDK r##a-e?) are recommended to be used during test/dev for a version (or a clearer example if the above was true. Many people had the same errors I did and worked through, so I know I am not alone in this confusion. We can improve this documentation to improve on-boarding clarity if you needed justification. ;)

orionnoir commented 7 years ago

NDK r11c compiles at the console with the latest Android SDK with the downgraded tools (downgraded to r25.2.5 using the Android SDK Manager)

ndk_r11c (March 2016) Windows 32-bit : (http://dl.google.com/android/repository/android-ndk-r11c-windows-x86.zip) Windows 64-bit : http://dl.google.com/android/repository/android-ndk-r11c-windows-x86_64.zip Mac OS X 64-bit : http://dl.google.com/android/repository/android-ndk-r11c-darwin-x86_64.zip Linux 64-bit (x86) : http://dl.google.com/android/repository/android-ndk-r11c-linux-x86_64.zip

Running the project in Android 2.3.3 studio resulted in success as well (after compiling at the cocos command line.) Hopefully that helps someone who stumbles on this thread!