是否可以更改默认风味根路径?
从:
---src
-----main
-----flavor1
-----flavor2
-----flavor3
至:
---src
-----main
-----flavors
--------flavor1
--------flavor2
--------flavor3
是否可以更改默认风味根路径?
从:
---src
-----main
-----flavor1
-----flavor2
-----flavor3
至:
---src
-----main
-----flavors
--------flavor1
--------flavor2
--------flavor3
如果您不想在每次添加风味时都在 sourceSets 中添加一行,则可以使用这样的闭包
productFlavors{
flavor1 {}
flavor2 {}
all { flavor ->
sourceSets[flavor.name].setRoot("src/flavors/${flavor.name}")
}
}
您可以通过使用sourceSets
.
productFlavors {
flavor2 {
}
flavor1 {
}
}
sourceSets{
flavor2 {
manifest.srcFile 'AndroidManifest-flavor2.xml'
res.srcDirs = ['res-flavor2', 'res']
java.srcDirs = ['src/flavor2/java','src/commonFiles/java']
resources.srcDirs = ['src/flavor2/java','src/commonFiles/java']
aidl.srcDirs = ['src/flavor2/java','src/commonFiles/java']
renderscript.srcDirs = ['src/flavor2/java','src/commonFiles/java']
}
flavor1 {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/flavor1/java','src/commonFiles/java']
resources.srcDirs = ['src/flavor1/java','src/commonFiles/java']
aidl.srcDirs = ['src/flavor1/java','src/commonFiles/java']
renderscript.srcDirs = ['src/flavor1/java','src/commonFiles/java']
res.srcDirs = ['res-flavor1','res']
assets.srcDirs = ['assets']
}
}
诚然,这可以实现,sourceSets
但正确且更简单的解决方案是:
productFlavors{
flavor1 {}
flavor2 {}
}
sourceSets{
flavor1.setRoot('src/flavors/flavor1')
flavor2.setRoot('src/flavors/flavor2')
}