dependencies {
implementation 'com.jakewharton.timber:timber:5.0.1'
}
import timber.log.Timber;
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
}
}
}
import timber.log.Timber;
public class MyActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Timber.d("onCreate called.");
}
}
如果仍然无法显示 Timber 日志,请尝试在 Android Studio 的 Logcat 窗口中选择“NO FILTERS”,然后输入关键字“Timber”并点击搜索按钮。