Why did Android Studio change all my references fr

2019-07-18 10:31发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-18 10:52

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:

Screen shot of the Editor > Auto Import preferences dialog

查看更多
登录 后发表回答