[英]Android: Are there any methods to share a resource betwwen different falvors and sourceset?
I have an application with below source sets and flavors: flavorDimensions "brand"我有一个具有以下源集和风味的应用程序:flavorDimensions “brand”
productFlavors {
flavor1 {
dimension "brand"
sourceSets {
main {
manifest.srcFile "src/main/flavor1/AndroidManifest.xml"
resources.srcDirs = ['src/flavor1/']
}
}
}
flavor2 {
dimension "brand"
sourceSets {
main {
manifest.srcFile "src/main/flavor2/AndroidManifest.xml"
resources.srcDirs = ['src/flavor2/']
}
}
}
flavor3 {
dimension "brand"
sourceSets {
main {
manifest.srcFile "src/main/flavor3/AndroidManifest.xml"
resources.srcDirs = ['src/flavor3/']
}
}
}
My application is such that 99% of layouts and classes are the same.我的应用程序是这样的,99% 的布局和类是相同的。 Eg only layout file
main_activity.xml
is different among flavors but the other 20~30 layout files are completely the same.例如,只有布局文件
main_activity.xml
的风格不同,但其他 20~30 个布局文件完全一样。 I don't want to copy these 20~30 in three different flavor source set.我不想将这 20~30 个复制到三个不同的风味源集中。 Are there any ways to share them among three flavors and if a file was present in source set, it overrides the share files?
有没有办法在三种风格之间共享它们,如果源集中存在文件,它会覆盖共享文件? (Such as want android does for
drawable
and drawble-hdpi
, ...)? (比如想要 android 为
drawable
和drawble-hdpi
做,...)? So I don't want to have所以我不想拥有
Unless I have misunderstood the question, you could solve the issue by changing build.gradle like this:除非我误解了这个问题,否则您可以通过像这样更改 build.gradle 来解决问题:
productFlavors {
flavor1 {
dimension "brand"
}
flavor2 {
dimension "brand"
}
//...
}
and structuring your app module like this:并像这样构建您的应用程序模块:
/src
/main
/flavor1
/flavor2
...
and placing all common files(source, resources) in main and the custom/specific files in the flavorX folders which will cause gradle to replace the identically named files in main when each flavor is built.并将所有公共文件(源、资源)放在 main 中,并将自定义/特定文件放在 flavorX 文件夹中,这将导致 gradle 在构建每个风味时替换 main 中的同名文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.