全部配置 / KN-BINARY-UNITSUSPENDFUNCTIONOBJCEXPORT
-Xbinary=unitSuspendFunctionObjCExport
Xbinary=unitSuspendFunctionObjCExport · KN-BINARY-UNITSUSPENDFUNCTIONOBJCEXPORT · 编译器参数(Native)
重要:中 · 场景相关
默认:未设置(不传则空)
场合:场景可配
来源:上游原样
默认值:未设置。未指定时由消费侧决定;未核对前不写死取值。使用场合:场景可配。场景可配:有明确目标(性能、包体、安全、兼容)时再改。
它是做什么的
用途。控制 Unit 挂起函数导出到 Objective-C 的方式。
影响。影响 Apple/ObjC/Swift 互操作或打包元数据;配错会导致导出/链接问题。
适用场景。Apple 目标互操作或打包;非 Apple 目标通常无关。
取值说明
| 可写取值 | 含义 | 使用场景 |
|---|---|---|
legacy | In this mode suspend functions and methods with [Unit] return type are exported to Objective-C with an additional argument, continuation callback, with the following Objective-C signature: `(^)(KtKotlinUnit * _Nullable, NSError * _Nullable)`. | — |
proper | In this mode suspend functions and methods with [Unit] return type are exported to Objective-C with an additional argument, continuation callback, with the following Objective-C signature: `(^)(NSError * _Nullable)`. Methods overriding superclass methods or implementing interface requirements narrowing down a more general return type to [Unit] are exported like in [LEGACY] mode. Note that in Swift 5.5 and higher suspend functions exported this way are transparently mapped to async functions with `Void` return type | — |
定义依据:konan/BinaryOptions.kt 在仓库中打开; konan/UnitSuspendFunctionObjCExport.kt 在仓库中打开
怎么用
- 配置入口:build.gradle.kts → ohosArm64.binaries.all { freeCompilerArgs += "-Xbinary=unitSuspendFunctionObjCExport=true" }
- 示例:
// 文件:build.gradle.kts(应用的 Kotlin 模块,例如 composeApp)
kotlin {
ohosArm64 { // 按实际 native target 调整
binaries.all {
freeCompilerArgs += "-Xbinary=unitSuspendFunctionObjCExport=true"
}
}
}
- 生效:Sync 后执行该目标的 compile/link。
- 验证:编译日志出现 `-Xbinary=unitSuspendFunctionObjCExport=true`。
- 回滚:从 binaries.all 的 freeCompilerArgs 中删除该项后 Clean 并重编。
- 注意:实验项无稳定兼容保证;改前留可回滚配置。
默认行为 未设置
不写这个配置时,编译器会怎么处理?
此选项默认未设置(空列表 / 空映射 / null)。不设置时由其他逻辑决定行为或直接跳过。
未指定时由消费侧决定;未核对前不写死取值。