Android Studio build APK error: __stack_chk_fail_local

I recently migrated from Unity to Cocos Creator and using Cocos 3.5.0. So, my experiences in Cocos Creator is like a newborn baby. The cute one.

So, then I have a problem when trying to build .APK file using Android Studio. It somehow throw me this error:

Build command failed.
Error while executing process D:\_dev\android\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\minkymomo\2022\github_repo\main_refactor_0904\trunk\build\android-001\proj\build\cmake\debug\x86 cocos}
ninja: Entering directory `D:\minkymomo\2022\github_repo\main_refactor_0904\trunk\build\android-001\proj\build\cmake\debug\x86'
[1/1] Linking CXX shared library D:\minkymomo\2022\github_repo\main_refactor_0904\trunk\build\android-001\proj\build\MuscleMan\intermediates\cmake\debug\obj\x86\libcocos.so
FAILED: D:/minkymomo/2022/github_repo/main_refactor_0904/trunk/build/android-001/proj/build/MuscleMan/intermediates/cmake/debug/obj/x86/libcocos.so 
cmd.exe /C "cd . && D:\_dev\android\ndk\25.0.8775105\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=i686-none-linux-android21 --sysroot=D:/_dev/android/ndk/25.0.8775105/toolchains/llvm/prebuilt/windows-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  -frtti -fexceptions -fsigned-char -fno-limit-debug-info  -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libcocos.so -o D:\minkymomo\2022\github_repo\main_refactor_0904\trunk\build\android-001\proj\build\MuscleMan\intermediates\cmake\debug\obj\x86\libcocos.so @CMakeFiles/cocos.rsp  && cd ."
ld: error: undefined hidden symbol: __stack_chk_fail_local
>>> referenced by uv-common.o:(uv__unknown_err_code) in archive D:/CocosDashboard/resources/.editors/Creator/3.5.0/resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
>>> referenced by uv-common.o:(uv_ip6_addr) in archive D:/CocosDashboard/resources/.editors/Creator/3.5.0/resources/resources/3d/engine/native/external/cmake/../android/x86/libuv.a
>>> referenced by inet.o:(inet_ntop4) in archive D:/CocosDashboard/resources/.editors/Creator/3.5.0/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.

Below is the build.gradle from libcocos:main

android {
    ndkPath PROP_NDK_PATH
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger() // 33

    defaultConfig {
        minSdkVersion PROP_MIN_SDK_VERSION //21
        targetSdkVersion PROP_TARGET_SDK_VERSION //33
        versionCode 1
        versionName "1.0"
    }

But, when I run Debug, the debug.apk was successfully made and it’s runnable on the devices.

I am using Android Studio Chipmunk.

Anyone else having the same issue? Is there any fix/workaround for this?

I just found out that it only happen when I opt to use x86 and x86_64 in the build setting in Cocos.
After I removed both, the .APK compiled successfully. Why?

image

google might have removed x86 from the latest ndk version, try changing the ndk to a lower version eg: version 21.1.6352462 works with x86. It can be changed in cocos creator β†’ preferences β†’ external programs β†’ android ndk and then make a build with APP ABI x86 selected it should work fine.
P.S. you will need to download the lower ndk version first

ah, yes, now that you mentioned it…
Thank you sir

1 Like