After add images to drawable “Cannot resolve symbol R” issue not going away after clean, rebuild etc

…衆ロ難τιáo~ 提交于 2020-01-17 01:30:11

问题


I can't find a way to add images to drawable folder without getting "Cannot resolve symbol R" issue.

And once i get "Cannot resolve symbol R", I can't get rid of it by either clean, rebuild, sync, invalidate cache & restart solutions for the error. Only if i delete the files can I get the build to pass.

I am not sure what is wrong here.

Note: I am on Android Studio 2.1.1


回答1:


You are facing this issue because your drawable file name is either having any capital letter or starting with a number or containing any special character like @,*,$ etc. rename it the error will be gone.

You can use only small letters, underscore(_), numbers(not at beginning) & dot(.) in the name of drawable

For example the name could be ABC.png then rename it to abc.png and it will work.

1xYz.JPEG then rename it to _1xyz.jpeg

a@b.png then rename it to ab.png

After that clean and rebuild & there you Go..!!




回答2:


I had exactly the same problem, and it was that I downloaded an "image.jpeg" extension from Internet and directly changed the extension saving it like "image.png", but Android studio still recognized it like image.jpeg.

I realized that when using top menu Analyze-Inpect code.

Once the inspection is finished a new window called 'Inspection' appears and in the follow carpets appears next:

Android > Lint > Usability > Icons
Icon format does not match the file extension

     Misleading file extension; named .png but the file format is JPEG*



回答3:


I found that the extension of the file must match the actual format of the image.

For example, you will get this error if you changed the extension of an image from bmp to png and added it to the project



来源:https://stackoverflow.com/questions/37880746/after-add-images-to-drawable-cannot-resolve-symbol-r-issue-not-going-away-afte

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!