You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio Dolphin 2021.3.1中Timber日志无法显示求助

Android Studio Dolphin 2021.3.1 中 Timber 日志不可见的解决方法

问题说明

在Android Studio Dolphin 2021.3.1环境下,调用Timber.d()输出的日志无法在Logcat中显示,仅系统Log.d()的日志正常可见。

排查与解决步骤

1. 确认Timber已完成初始化

Timber必须在应用启动时初始化才能生效,需在自定义Application类中完成:

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        // 仅Debug环境初始化DebugTree
        if (BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }
    }
}

同时确保AndroidManifest.xml中注册了该Application:

<application
    android:name=".MyApplication"
    ...>
    <!-- 其他配置 -->
</application>

2. 检查Logcat过滤器设置

  • 确认Logcat的日志级别未设置为高于Debug(如Info、Warn),否则Timber.d()的日志会被过滤
  • 检查是否存在自定义过滤器,排除了Timber默认使用的类名标签

3. 验证Timber依赖是否正确添加

在Module级别的build.gradle文件中确认已添加Timber依赖:

dependencies {
    implementation 'com.jakewharton.timber:timber:5.0.1' // 可替换为最新稳定版本
}

添加后执行Gradle同步,确保依赖成功引入。

4. 自定义Timber标签(可选)

若默认类名标签不易识别,可自定义DebugTree指定统一标签:

Timber.plant(object : Timber.DebugTree() {
    override fun createStackElementTag(element: StackTraceElement): String {
        return "TimberLog: ${element.simpleName}"
    }
})

之后在Logcat中搜索自定义标签即可快速定位Timber日志。

内容的提问来源于stack exchange,提问作者oyeraghib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 03:20:16