导入库仅用于调试

时间:2017-07-13 09:14:37

标签: android stetho

我正在使用 stetho lib来调试我的应用。

摇篮:

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;

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

1 个答案:

答案 0 :(得分:1)

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

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

  

导入语句不能使其成为字节代码。

你需要改变 摇篮:

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'