【问题标题】:Gradle build fails with same string name for different productGradle 构建失败,不同产品的字符串名称相同
【发布时间】:2018-07-03 06:21:44
【问题描述】:

我有一个项目,其中我有相同的字符串名称,但基于下面的产品有不同的值

 <string name="no_storage" product="nosdcard">Insert SD card before using camera</string>
 <string name="no_storage" product="default">Insert SD card before using camera</string>

但是在使用 gradle 构建时,我收到以下错误

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':mergeDebugResources'
Error: Found item String/no_storage more than one time

有没有办法绕过这个检查或解决这个问题?

【问题讨论】:

  • 不同的产品是指不同的风格或不同的构建类型?
  • 我认为没有product 属性。您应该为不同的构建类型/风格使用不同的资源集

标签: android gradle android-gradle-plugin build.gradle


【解决方案1】:

您应该将字符串值放在适当的风味相关目录中:

src/nosdcard/res/strings.xml(去掉product="nosdcard"属性):

<string name="no_storage">Insert SD card before using camera</string>

src/main/res/stringx.xml(去掉product="default"属性):

<string name="no_storage">Insert SD card before using camera</string>

我假设default“产品”表示默认源集。详情请阅读documentation on build variants

【讨论】:

    猜你喜欢
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 2016-12-05
    相关资源
    最近更新 更多