[英]Android - dependencies and code separation (debug/release builds)
I have some code in my android application which I intend to keep only in debug-builds. 我在我的android应用程序中有一些代码,我打算只保留在debug-builds中。
I am aware of this approach: 我知道这种方法:
if (BuildConfig.DEBUG) {
//code here
}
However, the problem is that my code relies on external dependencies which I would also like to keep in debug builds only : 但是,问题是我的代码依赖于外部依赖项,我还想在调试版本中保留它们:
debugCompile "dependency1"
//this wont compile in release mode
if (BuildConfig.DEBUG) {
//code which references dependency1
}
Given that there is no conditional compilation in java, are there any solutions besides commenting out blocks of code manually every time (which is obviously a huge hassle)? 鉴于java中没有条件编译,除了每次手动注释代码块之外还有任何解决方案吗(这显然是一个巨大的麻烦)?
EDIT: Egor pointed me in the right direction and after doing some more reasearch on "source sets" I found an answer which PRECISELY describes my situation and provides an excellent solution: https://stackoverflow.com/a/31483962/5790273 编辑:Egor 指出我正确的方向,在做了一些关于“源集”的研究后,我找到了一个答案,它精确地描述了我的情况并提供了一个很好的解决方案: https ://stackoverflow.com/a/31483962/5790273
Put the code you only want to compile in debug mode under "src/debug/java", as described here . 将您想要在“src / debug / java”下调试模式下编译的代码放在此处 ,如此处所述。 Gradle allows you to use multiple source sets per build type and flavor, and will only compile those that are relevant for the build configuration.
Gradle允许您为每个构建类型和风格使用多个源集,并且仅编译与构建配置相关的源集。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.