android - 导入库仅用于调试

标签 android stetho

我正在使用 stetho 库来调试我的应用程序。

Gradle :

debugCompile 'com.facebook.stetho:stetho:1.4.1'
debugCompile 'com.uphyca:stetho_realm:2.0.0'

应用类:

if (BuildConfig.DEBUG) {
    Stetho.initialize(..);
}

但如果我需要创建一个发布版本,我必须每次都发表评论:

import com.facebook.stetho.Stetho; 
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;

如何向编译器显示这些库仅用于调试? 我们可以在不创建额外类的情况下使用注释或类似的东西对两行进行注释吗?

最佳答案

让未使用的导入保持原样。您的 if (BuildConfig.DEBUG) 方法完全有效。坦率地说,这是实现它的最佳方式。

未使用的导入对性能没有影响:reference .编译时间可能会略有增加,但运行时间不会增加。

Import statements don't make it to byte code.

你需要改变 Gradle :

debugCompile 'com.facebook.stetho:stetho:1.4.1'
debugCompile 'com.uphyca:stetho_realm:2.0.0'

compile 'com.facebook.stetho:stetho:1.4.1'
compile 'com.uphyca:stetho_realm:2.0.0'

关于android - 导入库仅用于调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45076313/

相关文章:

Stetho 在 chrome 版本 89.0.4389.72(官方构建)(x86_64) 中不起作用

安卓工作室 2.1.1 : "no usb devices or running emulators detected"

android - 无法解决:com.squareup.retrofit2:converter-jaxb:2.3.0

java - Android 水平轮(自定义)DatePicker 中的问题

android - 动态添加的 View 未出现

android - 带有 DBFlow 表和 Stetho 的重复 "id"列

android - chrome 检查开发工具显示不佳(用于 android 的 stetho)

java - Android 中的 JGraphT 实现

android - 在 Android 中保存和恢复整个 fragment 堆栈

android - 无法在 chrome 开发工具资源中调整列的大小