前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【错误记录】Android Studio 编译报错 ( Error: Duplicate resources | 使用 sourceSets 配置多个 res 资源不能有重复名称的资源 )

【错误记录】Android Studio 编译报错 ( Error: Duplicate resources | 使用 sourceSets 配置多个 res 资源不能有重复名称的资源 )

作者头像
韩曙亮
发布2023-03-30 15:18:06
4.2K0
发布2023-03-30 15:18:06
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

一、报错信息


在 Android Studio 项目中 , 在 build.gradle 中 使用

代码语言:javascript
复制
    sourceSets {
        main {
            res.srcDirs 'src/main/res', 'src/main/res2'
        }
    }

配置 , 同时配置多个 res 目录 ;

报错信息 :

代码语言:javascript
复制
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"string/app_name","path":"Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\main\\res\\values\\strings.xml"}},{"file":{"description":"string/app_name","path":"Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\main\\res2\\values\\strings.xml"}}],"tool":"Resource and asset merger"}
AGPBI: {"kind":"error","text":"Duplicate resources","sources":[{"file":{"description":"string/app_name","path":"Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\main\\res\\values\\strings.xml"}},{"file":{"description":"string/app_name","path":"Y:\\002_WorkSpace\\001_AS\\SVG\\app\\src\\main\\res2\\values\\strings.xml"}}],"tool":"Resource and asset merger"}

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> [string/app_name] Y:\002_WorkSpace\001_AS\SVG\app\src\main\res\values\strings.xml	[string/app_name] Y:\002_WorkSpace\001_AS\SVG\app\src\main\res2\values\strings.xml: Error: Duplicate resources

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s
49 actionable tasks: 1 executed, 48 up-to-date

二、解决方案


在 配置了

2

个 res 目录 ,'src/main/res', 'src/main/res2' ,

其中 " src/main/res2/values/string.xml " 内容为 :

代码语言:javascript
复制
<resources>
    <string name="app_name">SVG_res2</string>
    <string name="res2">res2</string>
</resources>

" src/main/res/values/string.xml " 内容为 :

代码语言:javascript
复制
<resources>
    <string name="app_name">SVG</string>
</resources>
2

个目录中 , 都有 <string name="app_name"> 属性 , 必须删除一个 , 才能编译通过 , 否则会报 Error: Duplicate resources 错误 ;

将 " src/main/res2/values/string.xml " 内容 删除 app_name 属性 , 修改为 :

代码语言:javascript
复制
<resources>
    <string name="res2">res2</string>
</resources>

之后正常编译通过 ;

在这里插入图片描述
在这里插入图片描述
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-05-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、报错信息
  • 二、解决方案
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档