在我的build.gradle
中,我有两种构建类型:
buildTypes {
debug {
debuggable true
}
release {
debuggable false
}
}
在我的Android项目的入口点MainApplication.create()
中,我实例化了一个类ApplicationComponent
。
我已将类ApplicationComponent
扩展为具有一些额外方法的类DebugApplicationComponent
。
我希望在debuggable
为true
的情况下,MainApplication.create()
应该实例化DebugApplicationComponent
而不是ApplicationComponent
。
但是我怎么在MainApplication.create()
中知道debuggable
是真的?
如果我在Cmd-click
上debuggable
,我会上一个名为DefaultBuildType
的课程。我不确定此类是什么,或者如何从MainApplication
引用它。
答案 0 :(得分:3)
只需使用
if (BuildConfig.DEBUG) {
//Do whatever you want
}
答案 1 :(得分:0)
您可以在app/build.gradle
配置文件中创建自己的变量。
buildTypes {
debug {
debuggable true
buildConfigField "Boolean", "LOG_REQUIRED", "true"
}
release {
debuggable false
buildConfigField "Boolean", "LOG_REQUIRED", "false"
}
}
并像这样BuilConfig.LOG_REQUIRED