Why did Android Studio change all my references from R to android.R?

偶尔善良 提交于 2019-12-11 04:06:56

问题


I made an error in an Android layout file (forgot the dp in my dimension), and upon rebuilding, Android Studio replaced all of my references to R.java (which, because of the erroneous build, did not generate) with android.R.java. Is this normal behavior? How do I disable this? Is this caused by allowing auto-imports?


回答1:


What's happening is that the error in your XML file is preventing your project's R.java from being generated during the build, and the IDE is seeing that your R references in the code could now unambiguously autocomplete to android.R, and the Add unambiguous imports on the fly setting is going ahead and doing that. Problem is, android.R is the wrong import, when it really should wait for R.java to resolve.

If you want to leave Add unambiguous imports on the fly set, please add android.R to the Exclude from Import and Completion list in Preferences > Editor > Auto Import as shown here:



来源:https://stackoverflow.com/questions/21102497/why-did-android-studio-change-all-my-references-from-r-to-android-r

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