From e934d33cfa6f235c918fbdd50cdd37f92a229929 Mon Sep 17 00:00:00 2001 From: xfy Date: Mon, 25 May 2026 15:15:29 +0800 Subject: [PATCH] =?UTF-8?q?cleanup:=20ComposeTrace=20=E4=BB=85=E5=9C=A8=20?= =?UTF-8?q?debug=20=E6=9E=84=E5=BB=BA=E4=B8=AD=E5=90=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - core/build.gradle.kts: 启用 buildConfig 生成 - ComposeTrace: 添加 BuildConfig.DEBUG 条件,release 构建中空操作 避免 R8 full mode 下 Trace 调用的生产环境开销 Co-Authored-By: Claude Opus 4.7 (1M context) --- core/build.gradle.kts | 1 + core/src/main/kotlin/plus/rua/project/ComposeTrace.kt | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 2911c9e..2387cc1 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -16,6 +16,7 @@ android { buildFeatures { compose = true + buildConfig = true } compileOptions { diff --git a/core/src/main/kotlin/plus/rua/project/ComposeTrace.kt b/core/src/main/kotlin/plus/rua/project/ComposeTrace.kt index e68985e..c9bbfd0 100644 --- a/core/src/main/kotlin/plus/rua/project/ComposeTrace.kt +++ b/core/src/main/kotlin/plus/rua/project/ComposeTrace.kt @@ -1,12 +1,14 @@ package plus.rua.project import android.os.Trace +import plus.rua.project.shared.BuildConfig /** * Systrace 包装,用于录制 Compose 性能 trace。 - * Android 实际调用 android.os.Trace。 + * 仅在 debug 构建中启用,release 构建中为空操作。 */ fun composeTraceBeginSection(name: String) { + if (!BuildConfig.DEBUG) return try { Trace.beginSection(name) } catch (_: RuntimeException) { @@ -15,6 +17,7 @@ fun composeTraceBeginSection(name: String) { } fun composeTraceEndSection() { + if (!BuildConfig.DEBUG) return try { Trace.endSection() } catch (_: RuntimeException) {