You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio报错:String/button重复定义,寻求解决方案

Fixing "Found item String/button more than one time" Error in Android Studio

Hey there, let's get this duplicate string resource error sorted out—it's a pretty common hiccup when working with Android resources, so we'll have you back on track quickly.

What's causing this error?

This message pops up because you've duplicated the button string resource in your project's resource files. Android strictly enforces unique resource IDs, so having two <string name="button"> entries (either in the same strings.xml file or across different localization/value folders) will trigger this error.

Step-by-step fixes:

  1. Locate the duplicate entries

    • Switch to the Project view in Android Studio (instead of the default Android view) to see all your resource folders clearly.
    • Expand res/values and check every strings.xml file here—including localized versions like values-fr/strings.xml or values-de/strings.xml if you have them.
    • For a faster search, use the global search shortcut: Ctrl+Shift+F (Windows/Linux) or Cmd+Shift+F (Mac). Search for <string name="button"> to find all instances of this resource.
  2. Remove or merge the duplicates

    • If you accidentally added the same button string twice in the same file, just delete one of the entries. For example, delete the redundant line below:
      <!-- Keep this one -->
      <string name="button">Submit</string>
      <!-- Delete this duplicate -->
      <string name="button">Send</string>
      
    • If you have the same button resource in multiple language-specific strings.xml files, that's totally normal (it's how localization works!). The problem only occurs when the same file has duplicate entries.
  3. Clean and rebuild your project

    • After fixing the duplicates, head to the top menu bar: Build > Clean Project, then Build > Rebuild Project. This clears any cached resource data and ensures your changes are applied properly.

Extra check for multi-module projects

If your app has multiple modules, don't forget to check each module's res/values/strings.xml files too—duplicate resource IDs across modules can also trigger this error.

内容的提问来源于stack exchange,提问作者Muhammad Ashraf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:01:01