导入库仅用于调试 [英] Import library only for debugging

查看:114
本文介绍了导入库仅用于调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 stetho lib调试我的应用程序.

I am using stetho lib for debugging my app.

等级:

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

应用程序类:

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

但是,如果我需要创建发行版本,则每次都必须发表评论:

But if I need to create a release version I must comment every time:

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

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

How to show the compiler that these libs only for debugging? Can we comment on two lines without creating an additional class, using annotations or something like this?

推荐答案

只需保留未使用的导入.您的if (BuildConfig.DEBUG)方法是完全有效的.坦率地说,这是实现它的最佳方法.

Just leave the unused imports as they are. Your approach of if (BuildConfig.DEBUG) is perfectly valid. And frankly the best way to implement it.

未使用的进口对性能没有影响:参考.编译时间可能微不足道的增加,但是运行时却没有增加.

Unused imports have no impact on performance: reference. There might be a trivial increase in compile time, but no increase in runtime.

导入语句不会将其转换为字节码.

Import statements don't make it to byte code.

您需要进行更改 摇篮:

You will need to change 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'

这篇关于导入库仅用于调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆