使用 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)吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)