我有一个带有Java类的Android应用程序。
flavorDimensions "flavor"
productFlavors {
flavor1 {
dimension "flavor"
applicationId "net.flavor1"
}
flavor2{
dimension "flavor"
applicationId "net.flavor2"
}
}
sourceSets {
flavor1 {
java.srcDirs = ['src/main/java/net.flavor1/Configuration.java']
}
flavor2{
java.srcDirs = ['src/flavor2/Configuration.java']
}
}
只需在src/flavor1
和src/flavor2
中添加类的不同版本(在相同的软件包结构中)。您无需添加这些java.srcDirs
设置。例如,如果您的Configuration
类位于com.example
软件包中,那么您将拥有
src/flavor1/com/example/Configuration.java
src/flavor2/com/example/Configuration.java
在每种口味下添加versionName
和versionCode
。如果您将其留空。Gradle将使用默认一个
flavorDimensions "flavor"
productFlavors {
flavor1 {
dimension "flavor"
applicationId "net.flavor1"
versionName "2.0.1"
versionCode 31
}
flavor2{
dimension "flavor"
applicationId "net.flavor2"
versionName "1.0.1"
versionCode 3
}
}
sourceSets {
flavor1 {
java.srcDirs = ['src/main/java/net.flavor1/Configuration.java']
}
flavor2{
java.srcDirs = ['src/flavor2/Configuration.java']
}
}