使用官方demo编译到android平台失败

【问题概述】 使用官方的2D demo, hello world 直接导出后使用android studio编译, 无法成功编译。

  • Creator 版本: 3.8.1

  • 目标平台: Android

  • 重现方式: 直接使用官方demo,如图配置,进行编译。

  • 首个报错:

> Task :helloworld2:buildCMakeRelWithDebInfo[x86][cocos] FAILED
C/C++: ninja: Entering directory `/Users/chendongsheng/helloworld/build/android/proj/build/RelWithDebInfo/3jtl8681/x86'
C/C++: [1/1] Linking CXX shared library /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so
C/C++: FAILED: /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so 
C/C++: : && /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=i686-none-linux-android21 --sysroot=/Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fsigned-char -ffunction-sections -fdata-sections -fstrict-aliasing -frtti -fexceptions -fvisibility=hidden -fvisibility-inlines-hidden -O2 -g -DNDEBUG  -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--no-undefined-version -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments  -u GameActivity_onCreate -Wl,--gc-sections   -Wl,--gc-sections -shared -Wl,-soname,libcocos.so -o /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so CMakeFiles/cocos.dir/Users/chendongsheng/helloworld/native/engine/common/Classes/Game.cpp.o  -Wl,--whole-archive  libcocos_jni.a  -Wl,--no-whole-archive  libcocos_engine.a  -llog  libandroid_platform.a  -landroid  libpaddleboat_static.a  -lOpenSLES  /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/i686-linux-android/21/libEGL.so  -ljnigraphics  boost/container/libboost_container.a  libpvmp3dec.a  libvorbisidec.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libinspector.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libjpeg.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libpng.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libwebp.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libz.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libv8_monolith.a  -latomic -lm && :
C/C++: ld.lld: error: undefined hidden symbol: __stack_chk_fail_local
C/C++: >>> referenced by async.o:(uv__async_io) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
C/C++: >>> referenced by async.o:(uv__async_start.part.0) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
C/C++: >>> referenced by android-ifaddrs.o:(getResultList) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
C/C++: >>> referenced 26 more times
C/C++: clang++: error: linker command failed with exit code 1 (use -v to see invocation)
C/C++: ninja: build stopped: subcommand failed.
: && /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=i686-none-linux-android21 --sysroot=/Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fsigned-char -ffunction-sections -fdata-sections -fstrict-aliasing -frtti -fexceptions -fvisibility=hidden -fvisibility-inlines-hidden -O2 -g -DNDEBUG  -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--no-undefined-version -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments  -u GameActivity_onCreate -Wl,--gc-sections   -Wl,--gc-sections -shared -Wl,-soname,libcocos.so -o /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so CMakeFiles/cocos.dir/Users/chendongsheng/helloworld/native/engine/common/Classes/Game.cpp.o  -Wl,--whole-archive  libcocos_jni.a  -Wl,--no-whole-archive  libcocos_engine.a  -llog  libandroid_platform.a  -landroid  libpaddleboat_static.a  -lOpenSLES  /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/i686-linux-android/21/libEGL.so  -ljnigraphics  boost/container/libboost_container.a  libpvmp3dec.a  libvorbisidec.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libinspector.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libjpeg.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libpng.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libwebp.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libz.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libv8_monolith.a  -latomic -lm && :

ld.lld: error: undefined hidden symbol: __stack_chk_fail_local
>>> referenced by async.o:(uv__async_io) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
>>> referenced by async.o:(uv__async_start.part.0) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
>>> referenced by android-ifaddrs.o:(getResultList) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
>>> referenced 26 more times

: && /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=i686-none-linux-android21 --sysroot=/Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fsigned-char -ffunction-sections -fdata-sections -fstrict-aliasing -frtti -fexceptions -fvisibility=hidden -fvisibility-inlines-hidden -O2 -g -DNDEBUG  -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--no-undefined-version -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments  -u GameActivity_onCreate -Wl,--gc-sections   -Wl,--gc-sections -shared -Wl,-soname,libcocos.so -o /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so CMakeFiles/cocos.dir/Users/chendongsheng/helloworld/native/engine/common/Classes/Game.cpp.o  -Wl,--whole-archive  libcocos_jni.a  -Wl,--no-whole-archive  libcocos_engine.a  -llog  libandroid_platform.a  -landroid  libpaddleboat_static.a  -lOpenSLES  /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/i686-linux-android/21/libEGL.so  -ljnigraphics  boost/container/libboost_container.a  libpvmp3dec.a  libvorbisidec.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libinspector.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libjpeg.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libpng.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libwebp.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libz.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libv8_monolith.a  -latomic -lm && :

clang++: error: linker command failed with exit code 1 (use -v to see invocation)


Execution failed for task ':helloworld2:buildCMakeRelWithDebInfo[x86][cocos]'.
> com.android.ide.common.process.ProcessException: ninja: Entering directory `/Users/chendongsheng/helloworld/build/android/proj/build/RelWithDebInfo/3jtl8681/x86'
  [1/1] Linking CXX shared library /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so
  FAILED: /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so 
  : && /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=i686-none-linux-android21 --sysroot=/Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security   -fsigned-char -ffunction-sections -fdata-sections -fstrict-aliasing -frtti -fexceptions -fvisibility=hidden -fvisibility-inlines-hidden -O2 -g -DNDEBUG  -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--no-undefined-version -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments  -u GameActivity_onCreate -Wl,--gc-sections   -Wl,--gc-sections -shared -Wl,-soname,libcocos.so -o /Users/chendongsheng/helloworld/build/android/proj/build/helloworld2/intermediates/cxx/RelWithDebInfo/3jtl8681/obj/x86/libcocos.so CMakeFiles/cocos.dir/Users/chendongsheng/helloworld/native/engine/common/Classes/Game.cpp.o  -Wl,--whole-archive  libcocos_jni.a  -Wl,--no-whole-archive  libcocos_engine.a  -llog  libandroid_platform.a  -landroid  libpaddleboat_static.a  -lOpenSLES  /Users/chendongsheng/Library/Android/sdk/ndk/26.1.10909125/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/lib/i686-linux-android/21/libEGL.so  -ljnigraphics  boost/container/libboost_container.a  libpvmp3dec.a  libvorbisidec.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libinspector.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libjpeg.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libpng.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libwebp.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libz.a  /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/v8/libv8_monolith.a  -latomic -lm && :
  ld.lld: error: undefined hidden symbol: __stack_chk_fail_local
  >>> referenced by async.o:(uv__async_io) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
  >>> referenced by async.o:(uv__async_start.part.0) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
  >>> referenced by android-ifaddrs.o:(getResultList) in archive /Applications/Cocos/Creator/3.8.1/CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
  >>> referenced 26 more times
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.



Android Studio Giraffe | 2022.3.1 Patch 2
Build #AI-223.8836.35.2231.10811636, built on September 15, 2023
Runtime version: 17.0.6+0-17.0.6b829.9-10027231 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.0
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 16
Metal Rendering is ON
Registry:
    external.system.auto.import.disabled=true
    ide.text.editor.with.preview.show.floating.toolbar=false


It’s seem the x86 version build will always failed due to some link problems.
And if I single compiler arm-64 type apk, It’s will work fine with my android phone.

But I want using x86 version to debug for my android emlulator type is x86.

Download this https://github.com/cocos/cocos-engine-external/raw/v3.8.2/android/x86/libuv.a

,replace it in your engine directory and try again.

报了同样的问题,下载文件后放在什么地方啊

windows:你的 creator 安装根目录/resources/3d/engine/native/external/android/x86

mac 的:CocosCreator.app/Contents/Resources/resources/3d/engine/native/external/android/x86