Android Studio: Not Ready For Prime Time
As one would expect with a fine product, it would work best right out of the box. In the case of Android Studio, some assembly is required. The issue I found was that a newly created project with default settings wouldn’t compile. I thought that this bug might have been specific to my setup, but after reproducing it on 3 different computers and finding several outstanding questions as well as a few open bugs with Google concerning the issue, I decided that a fix would be a fine thing to write up, hoping it enables other people to develop as painlessly as possible.
Try creating a new project, giving a module name, a package name, etc. For this example, the project will be called “projectx.” Once the project is created, go look at your main activitiy’s layout file. You’ll get a warning that is something to the effect of “URI is not registered.“
In the Event Log you should also see “Android frame is detected in the project Configure.” From here go to File > Project Structures > Facets. Add an Android Facet and note where Android Studio is looking for the files: in the first level of the project.
Clicking on the ellipses will bring you to the project tree.
Here you can see that Android Studio has stopped looking for the appropriate files a few levels too high. Adjust all 4 components of the facet to point to the appropriate files and click “OK.”
Return to your layout file. Now, you errors should be resolved and you can code on your Android project to your hearts content.
On a hopeful note, I see that Android Studio 0.3.0 was released last Friday. It can be downloaded here. This version seems to have fixed the issue, but hasn’t been added to the sdk site as of yet. So the fix will still apply to those of you who are downloading from the SDK site. Note that if you are running Android Studio < 0.2.13 on Mac, you will have to uninstall and fresh install due to a bug. The release notes are here.
This bug probably resulted from the development team updating Gradle and the Gradle structure but not updating the Android project structure to match it. Thankfully it wasn’t too hairy to fix and only required adding a facet to account for the new structure. Going forward I hope the Android Studio dev team will try to keep the default projects in a friendlier state for all the junior devs out there.