0
点赞
收藏
分享

微信扫一扫

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



文章目录

  • ​​一、报错信息​​
  • ​​二、解决方案​​






一、报错信息


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

sourceSets {
main {
res.srcDirs 'src/main/res', 'src/main/res2'
}
}

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

报错信息 :

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


二、解决方案


在 配置了 【错误记录】Android Studio 编译报错 ( Error: Duplicate resources | 使用 sourceSets 配置多个 res 资源不能有重复名称的资源 )_android 个 res 目录 ,​​​'src/main/res', 'src/main/res2'​​ ,

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

<resources>
<string name="app_name">SVG_res2</string>
<string name="res2">res2</string>
</resources>

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

<resources>
<string name="app_name">SVG</string>
</resources>

【错误记录】Android Studio 编译报错 ( Error: Duplicate resources | 使用 sourceSets 配置多个 res 资源不能有重复名称的资源 )_android 个目录中 , 都有 ​​​<string name="app_name">​​ 属性 , 必须删除一个 , 才能编译通过 , 否则会报 Error: Duplicate resources 错误 ;

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

<resources>
<string name="res2">res2</string>
</resources>

之后正常编译通过 ;

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



举报

相关推荐

0 条评论