使用 gradle 构建特定的 Android Product Flavor 时,我可以排除区域资源(例如 values

Can I exclude regional resources (e.g. values-fr) when building a particular Android Product Flavor with gradle(使用 gradle 构建特定的 Android Product Flavor 时,我可以排除区域资源(例如 values-fr)吗)
本文介绍了使用 gradle 构建特定的 Android Product Flavor 时,我可以排除区域资源(例如 values-fr)吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

假设我有这个目录结构:

Say I have this directory structure:

app
--src
   |--main
   |   |--java
   |   |--res
   |       |--drawable
   |       |--values
   |       |--values-fr
   |       |--values-de
   |
   |--flavor1
   |   |--res
   |       |--drawable
   |
   |--flavor2
   |   |--res
   |       |--drawable
   |
   |--flavor3
       |--res
           |--drawable

values-fr 对于 flavor1flavor2 都是通用的,因此 valuesvalues-frvalues-de 应该被打包

values-fr is common for both flavor1 and flavor2, and so values, values-fr and values-de should get packaged

flavor3 应该只打包 valuesvalues-de.所以我只需要从 flavor3 中排除 values-fr 资源文件夹.

flavor3 should only package values and values-de. So I need to exclude the values-fr resource folder from the flavor3 only.

我已经尝试了很多组合,例如下面的组合,但无法弄清楚,或者即使有可能.

I've tried loads of combinations such as those below, but cannot figure it out, or even if it's possible.

sourceSets {
    flavor3 {
        res.exclude 'values-fr/**'
        res.exclude 'values-fr/'
    }
}

<小时>

编辑

对于上面的示例,我发现这个包含仅德语的工作解决方案使用:

I found this working solution to include only German for the above example using:

productFlavors {
    flavour3 {
        resConfigs 'de' // include '-de' resources, along with default 'values'
    }
}

您还可以在这里查看ICU的国家代码列表.

You can also check the list of country codes from ICU here.

推荐答案

最终的工作解决方案是包含一种语言 - 在这种情况下,只有德语(de):

The final working solution is to include a language - in this case, only German (de):

productFlavors {
    flavour3 {
        resConfigs 'de' // include '-de' resources, along with default 'values'
    }
}

作为参考,您还可以查看 ICU 这里的国家代码列表.

As a reference, you can also check the list of country codes from ICU here.

这篇关于使用 gradle 构建特定的 Android Product Flavor 时,我可以排除区域资源(例如 values-fr)吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)