全部配置 / KN-BINARY-OBJCEXPORTSUSPENDFUNCTIONLAUNCHTHREADRESTRICTION
-Xbinary=objcExportSuspendFunctionLaunchThreadRestriction
Xbinary=objcExportSuspendFunctionLaunchThreadRestriction · KN-BINARY-OBJCEXPORTSUSPENDFUNCTIONLAUNCHTHREADRESTRICTION · 编译器参数(Native)
重要:中 · 场景相关
默认:未设置(不传则空)
场合:场景可配
来源:上游原样
默认值:未设置。未指定时由消费侧决定;未核对前不写死取值。使用场合:场景可配。场景可配:有明确目标(性能、包体、安全、兼容)时再改。
它是做什么的
用途。限制 ObjC 导出挂起函数的启动线程。
影响。影响 Apple/ObjC/Swift 互操作或打包元数据;配错会导致导出/链接问题。
适用场景。Apple 目标互操作或打包;非 Apple 目标通常无关。
取值说明
| 可写取值 | 含义 | 使用场景 |
|---|---|---|
main | In this mode, suspend functions called from ObjC/Swift may only be called from the main thread | — |
none | In this mode, suspend functions called from ObjC/Swift may be called from any thread | — |
定义依据:konan/BinaryOptions.kt 在仓库中打开; konan/ObjCExportSuspendFunctionLaunchThreadRestriction.kt 在仓库中打开
怎么用
- 配置入口:build.gradle.kts → ohosArm64.binaries.all { freeCompilerArgs += "-Xbinary=objcExportSuspendFunctionLaunchThreadRestriction=true" }
- 示例:
// 文件:build.gradle.kts(应用的 Kotlin 模块,例如 composeApp)
kotlin {
ohosArm64 { // 按实际 native target 调整
binaries.all {
freeCompilerArgs += "-Xbinary=objcExportSuspendFunctionLaunchThreadRestriction=true"
}
}
}
- 生效:Sync 后执行该目标的 compile/link。
- 验证:编译日志出现 `-Xbinary=objcExportSuspendFunctionLaunchThreadRestriction=true`。
- 回滚:从 binaries.all 的 freeCompilerArgs 中删除该项后 Clean 并重编。
- 注意:实验项无稳定兼容保证;改前留可回滚配置。
默认行为 未设置
不写这个配置时,编译器会怎么处理?
此选项默认未设置(空列表 / 空映射 / null)。不设置时由其他逻辑决定行为或直接跳过。
未指定时由消费侧决定;未核对前不写死取值。