简体   繁体   English

Android:是否有任何方法可以在不同的 falvors 和 sourceset 之间共享资源?

[英]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 为drawabledrawble-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.

相关问题 将任何依赖项添加到其 sourceSet 后,Android Studio 未索引 commonMain 文件夹 - Android Studio isn't indexing commonMain folder after adding any dependencies to its sourceSet 如何使用 buildTypes、productFlavors 和 sourceSet 为不同的 android 渠道批量构建 apk - How to use buildTypes, productFlavors, and sourceSet to batch build apks for different android channels Flutter 风味源集资源不参考风味文件夹 - Flutter flavor sourceSet resource not refer flavor folder 比较不同方法的资源使用 - Comparing resource use of different methods 如何在Android中的两个edittext之间添加gridview - how to add gridview in betwwen two edittext in android Android:与其他应用程序共享可绘制资源 - Android : Share drawable resource with other apps Android - 在两个应用程序之间共享资源 - Android - Share resource between two applications Android Gradle插件无法识别SourceSet的“instrumentTest” - The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin Android Gradle 插件无法识别 SourceSet 'robolectric' - The SourceSet 'robolectric' is not recognized by the Android Gradle Plugin Android Gradle SourceSet资源不复制基本目录 - Android Gradle SourceSet Resources not copying base dir
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM