3.8打包安卓提示:error: no template named 'unary_function' in namespace 'std';

使用cocos自带的“生成”会提示该错误

2023-10-7 16:24:18-log: [runCmd ./gradlew] 71 actionable tasks: 11 executed, 60 up-to-date

2023-10-7 16:24:18-log: [runCmd ./gradlew - error] /Applications/Cocos/Creator/3.8.0/CocosCreator.app/Contents/Resources/resources/3d/engine/native/cocos/base/std/hash/hash.h:135:33: error: no template named ‘unary_function’ in namespace ‘std’; did you mean ‘__unary_function’?
struct hash_base : std::unary_function<T, hash_t> {};
~^~~~~~~~~~
__unary_function
/Users/tangbing/Library/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/c++/v1/__functional/unary_function.h:46:1: note: ‘__unary_function’ declared here
using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>;
^
2 warnings and 2 errors generated.
ninja: build stopped: subcommand failed.

C++ build system [build] failed while executing:
/Users/tangbing/Library/Android/sdk/cmake/3.22.1/bin/ninja
-C
/Users/tangbing/dyhc/block/build/android/proj/build/RelWithDebInfo/5ix84c5p/arm64-v8a
cocos
from /Users/tangbing/dyhc/block/native/engine/android/app

  • 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.

BUILD FAILED in 4s

2023-10-7 16:24:19-warn: failed to exec ./gradlew block:assembleRelease
2023-10-7 16:24:19-log: [task:make]: 构建插件 native 的钩子函数 make 执行失败,请检查插件的代码逻辑~, 23.333333333333332%
2023-10-7 16:24:19-log: [task:make]: failed to exec ./gradlew block:assembleRelease, 36.66666666666667%
2023-10-7 16:24:19-error: make package /Users/tangbing/dyhc/block/build/android failed!
2023-10-7 16:24:19-log: [task:make]: failed!
2023-10-7 16:24:19-debug: // ---- builder:run-build-stage-make ---- (6050ms)
2023-10-7 16:24:19-debug: [Build Memory track]: builder:build-stage-total make start:282.11MB, end 280.82MB, increase: -1315.23KB

又按照文档使用andorid studio打开·proj·目录后,进行build也提示:

error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
    struct hash_base : std::unary_function<T, std::size_t> {};
                       ~~~~~^~~~~~~~~~~~~~
                            __unary_function

我搜索到了都是关于xcode打包ios的信息,没有找到安卓的问题,请问有什么好的解决办法吗?或者更换cocos 版本?

2赞

{
“name”: “block”,
“server”: “”,
“platform”: “android”,
“buildPath”: “project://build”,
“debug”: false,
“md5Cache”: false,
“skipCompressTexture”: false,
“sourceMaps”: false,
“polyfills”: {
“asyncFunctions”: false
},
“experimentalEraseModules”: false,
“startSceneAssetBundle”: false,
“bundleConfigs”: [],
“useBuiltinServer”: false,
“mainBundleIsRemote”: false,
“mainBundleCompressionType”: “merge_dep”,
“useSplashScreen”: true,
“bundleCommonChunk”: false,
“packAutoAtlas”: true,
“startScene”: “6627f7eb-dc24-498e-a39b-588001bb9306”,
“outputName”: “android”,
“taskName”: “android”,
“scenes”: [
{
“url”: “db://assets/game.scene”,
“uuid”: “6627f7eb-dc24-498e-a39b-588001bb9306”
}
],
“packages”: {
“engine”: {
“cleanupImageCache”: “inheritProjectSetting”,
version”: “1.0.7”
},
“android”: {
“packageName”: “com.cc”,
“orientation”: {
“portrait”: true,
“upsideDown”: false,
“landscapeRight”: false,
“landscapeLeft”: false
},
“apiLevel”: 29,
“appABIs”: [
“arm64-v8a”
],
“useDebugKeystore”: false,
“keystorePath”: “/Users/xx/block_andorid_key”,
“keystorePassword”: “123213”,
“keystoreAlias”: “block-key”,
“keystoreAliasPassword”: “123213”,
“appBundle”: false,
“androidInstant”: false,
“inputSDK”: false,
“remoteUrl”: “”,
“sdkPath”: “”,
“ndkPath”: “”,
“renderBackEnd”: {
“vulkan”: false,
“gles3”: true,
“gles2”: true
},
“swappy”: false,
version”: “1.0.1”
},
“cocos-service”: {
“configID”: “7aea82”,
“services”: [],
version”: “3.0.7”
},
“native”: {
“encrypted”: false,
“xxteaKey”: “d8KSA4xT5OR5ahv+”,
“compressZip”: false,
“JobSystem”: “none”,
version”: “1.0.2”
}
},
version”: “1.3.6”,
“buildMode”: “normal”,
“logDest”: “project://temp/builder/log/android10-7-2023 15-21.log”
}

这是配置,都没怎么选,andorid api选的是29

1赞

俺3.7 打包也遇到这个问题 题主解决了吗

我也是啊,引擎组有没有临时解决方案呢?等3.8.2太慢了

3.7.0的也是这个问题

3.8打包同问题…

这个符号是引擎底层里面定义的, 我直接去引擎目录把这个符号改了。打包倒是正常了, 目前到没发现问题。只是如果需要打包其他原生可能还需要再改回来…

C:\ProgramData\cocos\editors\Creator\3.8.0\resources\resources\3d\engine\native\cocos\base\std\hash

struct hash_base : std::__unary_function<T, hash_t> {}

我改了以后,还是不行,别的地方又出问题了

NDK别用那么新的,用 android-ndk-r25c,就足够了。用最新的NDK,的确会出现这个问题。

什么都不要改,就用老的NDK就行,然后build.gradle里指定一下NDK的版本就行。