简体   繁体   English

在Android Studio中构建项目时出错“错误:找不到与给定名称匹配的资源(在____处使用值&#39;@ drawable / <name> “)

[英]Error Building Project in Android Studio "Error: No resource found that matches the given name (at ____ with value '@drawable/<name>')

I've searched all over Google, stackoverflow and other android programming websites, many have suggestions for people who have misplaced files from one folder to another and so forth.. But none that illustrate the problem I'm facing. 我搜遍了谷歌,stackoverflow和其他Android编程网站,很多人都建议那些把文件从一个文件夹放到另一个文件夹的人等等......但没有一个能说明我面临的问题。

It's not a corrupt file as in the case here as I tried this with no success. 它不像这里的情况那样是一个损坏的文件,因为我尝试了这个没有成功。

The error I'm facing is similar though: 我面临的错误是类似的:

[debug] C:\Users\Name\AppData\Local\Temp\android_manifest_copy6264790980678653632tmp\AndroidManifest.xml:11: error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/ic_launcher').

Similarly, this is happening with an @string element, @style element and another @string, examples below: 类似地,这发生在@string元素,@ style元素和另一个@string,下面的示例:

'@string/app_name'
'@style/AppTheme'
'@string/app_name'

One thing that I have noticed, and coming from the world of Eclipse, I cannot explain this behavior in Android Studio.. In my 'main' project folder, everything exists and builds correctly for debugging. 我注意到的一件事,来自Eclipse的世界,我无法在Android Studio中解释这种行为。在我的“主”项目文件夹中,一切都存在并且正确构建用于调试。 It seems that Android Studio is trying to build off of a 'debug' folder, which will not build when running 'Build' > 'Rebuild Project'. 似乎Android Studio正试图建立一个'debug'文件夹,在运行'Build'>'Rebuild Project'时不会构建。

Does anyone know where I can place these missing files to get the project to build? 有谁知道我可以在哪里放置这些丢失的文件来构建项目? Or is this some other problem? 或者这是另一个问题吗?

Alright, so after fussing with the rebuild for hours trying different methods (renaming particular files [ie those with the problems], rebuilding the app after renaming folders inside the build folder, etc) I finally decided that I would go to the source of the problem and see if it worked like other IDE's. 好吧,所以在重建几个小时后尝试不同的方法(重命名特定文件[即那些有问题],在重命名构建文件夹内的文件夹后重建应用程序等)我终于决定我会去的源头问题,看看它是否像其他IDE一样工作。 Indeed it did, this is how I performed the fix: 确实如此,这是我执行修复的方式:

  1. Find the location of the problem - For me, all four of the errors I had were inside the 'build' folder of the project. 找到问题的位置 - 对我来说,我所有的四个错误都在项目的“build”文件夹中。
  2. Close any open instances of the project 关闭项目的所有打开实例
  3. While the project is closed, rename this folder from windows explorer (or other if youre using a different OS) (ie If the folders name is "build", rename it to "build.old") 当项目关闭时,从Windows资源管理器(或其他如果您使用不同的操作系统)重命名此文件夹(即如果文件夹名称为“build”,则将其重命名为“build.old”)
  4. Open the project once more 再次打开项目
  5. Go to Build > Rebuild Project 转到“构建”>“重建项目”

You should not have any issues doing this, like I did. 像我一样,你不应该有任何问题。

Specifications: 产品规格:

  • IDE Platform: Android Studio IDE平台:Android Studio
  • IDE Version: Android Studio (I/O Preview) 0.2.2 IDE版本:Android Studio(I / O预览版)0.2.2
  • JRE: 1.7.0_25 JRE:1.7.0_25

My problem is about @drawable/img_1 , the pic is JPEG format, while it's extension name is png, I force to rename it jpg extension. 我的问题是关于@drawable/img_1 ,pic是JPEG格式,而它的扩展名是png,我强制重命名为jpg扩展名。 Then it builds successfully. 然后它成功构建。

If anyone is using Gradle and sees this it's good to remind about the convention directory structure. 如果有人正在使用Gradle并且看到这个,那么最好提醒一下约定目录结构。

For Gradle you have to put your resources in src/main/res. 对于Gradle,您必须将资源放在src / main / res中。 I migrated a project to Gradle and got the said error when I hadn't moved the res/ directory from the old structure. 当我没有从旧结构移动res /目录时,我将一个项目迁移到Gradle并得到了所述错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到与给定名称匹配的资源(在&#39;icon&#39;处,值为&#39;@ drawable / icon&#39;) - Error : No resource found that matches the given name (at 'icon' with value '@drawable/icon') Unity项目中的错误:找不到与给定名称匹配的资源(在“ icon”处,值为“ @ drawable / ic_launcher”) - Error in Unity project : No resource found that matches the given name (at 'icon' with value '@drawable/ic_launcher') apktool编译错误未找到与给定名称匹配的资源(在&#39;pointDrawable&#39;处,值为&#39;@ android:drawable / APKTOOL_DUMMY_0302&#39; - apktool compile error No resource found that matches the given name (at 'pointDrawable' with value '@ android:drawable/APKTOOL_DUMMY_0302' 错误的XML块,错误:找不到与给定名称匹配的资源(在&#39;icon&#39;处,值为&#39;@android:drawable - Bad XML block, Error: No resource found that matches the given name (at 'icon' with value '@android:drawable Android错误:找不到与Android Studio中的给定名称匹配的资源 - Android Error: No resource found that matches the given name in Android Studio 错误未找到与给定名称匹配的资源:Android Studio中的attr&#39;borderWidth&#39; - Error No resource found that matches the given name: attr 'borderWidth' in Android Studio 字体android studio 3错误:找不到与给定名称匹配的资源 - Error with fonts android studio 3: No resource found that matches the given name Android Studio - 错误:找不到与给定名称匹配的资源:attr&#39;metaButtonBarButtonStyle&#39; - Android Studio - Error: No resource found that matches the given name: attr 'metaButtonBarButtonStyle' Android Studio:错误:找不到与给定名称匹配的资源(在&#39;layout_above&#39;处,值为&#39;@ id / adView&#39;) - Android Studio: Error: No resource found that matches the given name (at 'layout_above' with value '@id/adView') 错误:找不到与给定名称匹配的资源(在“ src”处,值为“ @ drawable / googleg_standard_color_18”) - Error: No resource found that matches the given name (at 'src' with value '@drawable/googleg_standard_color_18')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM