全部配置 / KN-X

X

X · KN-X · 编译器参数(Native)

重要:低 · 工具/诊断 默认:—(无开关语义) 场合:排障诊断 来源:上游原样

默认值:—。打印 -X 帮助,无开关语义。使用场合:排障诊断。排障诊断:定位编译或运行问题时短时开启,结束后应关闭。

它是做什么的

用途。打印高级(-X)编译选项说明。原文:Print a synopsis of advanced options.

影响。实验/高级编译开关;默认保持关闭,改前需可复现、可回滚。

适用场景。编译期观察;不要写进产品默认模板。

取值说明

布尔 · 写法 -X(开启) · 默认 false(BooleanType.defaultFalse)

可写。(开关存在 / true) / false / 不传

定义依据:description/CommonToolArguments.kt 在仓库中打开

怎么用

  1. 配置入口:build.gradle.kts → ohosArm64.binaries.all { freeCompilerArgs += "-X" }
  2. 示例
// 文件:build.gradle.kts(应用的 Kotlin 模块,例如 composeApp)
kotlin {
  ohosArm64 {  // 按实际 native target 调整
    binaries.all {
      freeCompilerArgs += "-X"
    }
  }
}
  1. 生效:Sync 后执行该目标的 compile/link。
  2. 验证:编译日志出现 `-X`。
  3. 回滚:从 binaries.all 的 freeCompilerArgs 中删除该项后 Clean 并重编。
  4. 注意:实验项无稳定兼容保证;改前留可回滚配置。

默认行为

不写这个配置时,编译器会怎么处理?

此项无开关语义(如打印帮助、列出目标),不是运行时行为开关。

打印 -X 帮助,无开关语义。

相关文档

以下摘抄原文中与本配置最相关的段落,便于速读;完整上下文请点原文。

上游 · Kotlin compiler options · Common

-version

Display the compiler version.

-X

Display information about the advanced options and exit. These options are currently unstable: their names and behavior may be changed without notice.

Kotlin contract options

The following options enable experimental Kotlin contract features.

-Xallow-contracts-on-more-functions

Enables contracts in additional declarations, including property accessors, specific operator functions, and type assertions on generic types.

-Xallow-condition-implies-returns-contracts…

打开原文

溯源与对照

状态
实验(-X,兼容性不保证)
版本基线
2.2.21-1.0.0
定义位置类型
编译器参数定义(arguments DSL)
源码路径
compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonToolArguments.kt 在仓库中打开