全部配置 / KN-BINARY-LATIN1STRINGS

-Xbinary=latin1Strings

Xbinary=latin1Strings · KN-BINARY-LATIN1STRINGS · 编译器参数(Native)

重要:中 · 场景相关 默认:未设置(不传则空) 场合:场景可配 来源:上游原样

默认值:未设置。BinaryOptions 未声明默认;未核对消费侧前不标开关。使用场合:场景可配。场景可配:有明确目标(性能、包体、安全、兼容)时再改。

它是做什么的

用途。对 Latin-1 字符串使用更紧凑表示。示例取值:`latin1Strings=true`(Latin-1 紧凑字符串)。官方说明:Controls support for Latin-1-encoded strings to reduce application binary size and adjust memory consumption.

影响。主要影响包体;可能折中性能或可调试性。

适用场景。Release 或包体敏感场景评估;改后对比体积与性能。

取值说明

布尔 · 写法 -Xbinary=latin1Strings=true|false

可写。true / false

定义依据:konan/BinaryOptions.kt 在仓库中打开

怎么用

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

默认行为 未设置

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

此选项默认未设置(空列表 / 空映射 / null)。不设置时由其他逻辑决定行为或直接跳过。

BinaryOptions 未声明默认;未核对消费侧前不标开关。

相关文档

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

上游 · Kotlin/Native memory management

To enable it, set the following option in your gradle.properties file:

kotlin.native.binary.latin1Strings=true

With the Latin-1 support, strings are stored in Latin-1 encoding as long as all the characters fall within its range. Otherwise, the default UTF-16 encoding is used.

While the feature is Experimental, the cinterop extension functions String.pin , String.usePinned , and String.refTo become less efficient. Each call to them may trigger an automatic string conversion to UTF-16.

If none of these options helped, create an issue in YouTrack .…

打开原文

溯源与对照

状态
实验(-X,兼容性不保证)
版本基线
2.2.21-1.0.0
定义位置类型
Native 二进制选项(BinaryOptions / -Xbinary)
源码路径
kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/BinaryOptions.kt 在仓库中打开