Android的gradle这个buildTypes:重复类
我转换我的应用程序使用gradle这个,我试图用buildTypes。我有我想修改我的发布版本一常量
类。所以我必须在文件的src / main / JAVA /我/包/名/ Constants.java
和的src /发行/ JAVA /我的/包/名/ Constants.java
。
I'm converting my app to use gradle, and I'm trying to use the buildTypes. I have a Constants
class which I wish to modify for my release build. So I have a file at src/main/java/my/package/name/Constants.java
and at src/release/java/my/package/name/Constants.java
.
当我尝试建立这个,gradle这个告诉我,构建失败在我发布buildtype的常量
文件中,这是一个重复类错误。
When I try to build this, gradle tells me the build failed on the Constants
file in my release buildtype, with the error that it's a duplicate class.
我也试过在添加不同sourceSet为此我的build.gradle
是这样的:
I also tried adding a different sourceSet for this in my build.gradle
like this:
sourceSets {
main {
java.srcDirs = ['src/main/java'];
//...
}
release {
java.srcDirs = ['src/release/java'];
}
}
但是,这仍然给了我同样的错误。所以,我想知道,我究竟做错了什么?
But this still gives me the same error. So I'm wondering, what am I doing wrong here?
您不能在主
和发布$ C类$ C>。你需要像拆的东西
调试
和发布
。
You can not have a class in main
and release
. You need to split it to something like debug
and release
.
gradle这个将合并源设置每个 buildType
与主
。结果
这是什么原因,为什么类GET在你的复制发布
版本。
gradle will merge the source sets for each buildType
with main
.
This is the reason, why the class get's duplicated in your release
build.
所以规则是:把全班学生分成主
或每一个 buildType
但不能同时使用。
So the rule is: put a class into main
, or in every buildType
but not both.