2

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?

Phil
  • 35,852
  • 23
  • 123
  • 164
  • This sounds like a bug. Do you have a reproducible test case? If so we can file it, and maybe you can get some help on the question here. – Scott Barta Jan 13 '14 at 22:26
  • @ScottBarta I was able to replicate the bug, so made the report here: https://code.google.com/p/android/issues/detail?id=64802&thanks=64802&ts=1389711338 – Phil Jan 14 '14 at 14:56
  • @ScottBarta did this get fixed in the latest build (0.5.0 or 0.5.1)? – Phil Mar 11 '14 at 17:49
  • No, the bug is still open. I don't have an ETA. – Scott Barta Mar 11 '14 at 19:14
  • This bug is now fixed in the current release of Android Studio (confirmed about 25 minutes ago). – Phil May 14 '14 at 15:05

1 Answers1

8

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

Scott Barta
  • 79,344
  • 24
  • 180
  • 163
  • Nice! Thanks for getting back so fast. – Phil Jan 14 '14 at 17:27
  • Thanks for the diagnostic work on it. Without your step in the bug setting up imports a la http://stackoverflow.com/questions/16615038/what-is-the-shortcut-to-auto-import-all-in-android-studio, I would have never realized what was going on. – Scott Barta Jan 14 '14 at 17:28