From 49487a00e8c51c5c9cb9681bc877cf45e6288997 Mon Sep 17 00:00:00 2001 From: xfy Date: Tue, 19 May 2026 11:47:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ComposeTrace=20host=20test=20=E9=99=8D?= =?UTF-8?q?=E7=BA=A7=EF=BC=88Trace=20API=20=E6=9C=AA=20stub=20=E6=97=B6?= =?UTF-8?q?=E9=9D=99=E9=BB=98=E5=BF=BD=E7=95=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit androidHostTest 中 android.os.Trace 未提供 stub,调用会抛 RuntimeException。 包装在 try-catch 中,使 host test 能正常执行涉及 trace 的代码路径。 Co-Authored-By: Claude Opus 4.7 (1M context) --- .../plus/rua/project/ComposeTrace.android.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shared/src/androidMain/kotlin/plus/rua/project/ComposeTrace.android.kt b/shared/src/androidMain/kotlin/plus/rua/project/ComposeTrace.android.kt index af5faa7..a3f9403 100644 --- a/shared/src/androidMain/kotlin/plus/rua/project/ComposeTrace.android.kt +++ b/shared/src/androidMain/kotlin/plus/rua/project/ComposeTrace.android.kt @@ -2,6 +2,18 @@ package plus.rua.project import android.os.Trace -actual fun composeTraceBeginSection(name: String) = Trace.beginSection(name) +actual fun composeTraceBeginSection(name: String) { + try { + Trace.beginSection(name) + } catch (_: RuntimeException) { + // Trace API 在 host test 中未 stub;忽略 + } +} -actual fun composeTraceEndSection() = Trace.endSection() \ No newline at end of file +actual fun composeTraceEndSection() { + try { + Trace.endSection() + } catch (_: RuntimeException) { + // Trace API 在 host test 中未 stub;忽略 + } +} \ No newline at end of file