Can I exclude regional resources (e.g. values-fr)

2019-01-25 13:13发布

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 is common for both flavor1 and flavor2, and so values, values-fr and values-de should get packaged

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/'
    }
}

EDIT

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'
    }
}

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

2条回答
▲ chillily
2楼-- · 2019-01-25 14:05

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'
    }
}

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

查看更多
贼婆χ
3楼-- · 2019-01-25 14:10

You can exclude those folders by using this snippet:

sourceSets {
  flavor3 {
    main {
      resources {
        srcDir 'res'
        exclude '**/values-fr/**'
      }
    }
  }
}
查看更多
登录 后发表回答