Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Cannot Resolve symbol 'R'

When i was running my app build, it came back saying 2 errors and one of them was the R.java.

Went from working fine, to not. The only thing I differently from the working build to not working was added ImageView, only had one size.

This was the error from the Gradle Build:

Error:error: invalid symbol: 'import' Error:Execution failed for task ':app:processDebugResources'.

com.android.ide.common.internal.LoggedErrorException: Failed to run command: C:\android-studio-bundle-windows\android-studio\sdk\build-tools\android-4.4W\aapt.exe package -f --no-crunch -I C:\android-studio-bundle-windows\android-studio\sdk\platforms\android-19\android.jar -M C:\Users\Benjamin\AndroidStudioProjects\EmojiProject\app\build\intermediates\manifests\debug\AndroidManifest.xml -S C:\Users\Benjamin\AndroidStudioProjects\EmojiProject\app\build\intermediates\res\debug -A C:\Users\Benjamin\AndroidStudioProjects\EmojiProject\app\build\intermediates\assets\debug -m -J C:\Users\Benjamin\AndroidStudioProjects\EmojiProject\app\build\generated\source\r\debug -F C:\Users\Benjamin\AndroidStudioProjects\EmojiProject\app\build\intermediates\libs\app-debug.ap_ --debug-mode --custom-package projectClown.emojiproject -0 apk Error Code: 1 Output: res\menu\import.xml:0: error: invalid symbol: 'import'

Anyone else ran into problems like this?

1 Answer

Hello,

A couple of things you can try to do is to clean and rebuild your project by going to Build -> Clean Project, then Build -> Make Project.

Another option is to try and go to File -> Invalidate Caches/Restart, then select Invalidate and Restart.

Please let us know if this doesn't help and you need more assistance.

Ok, i'll try it. Why does it do that? Just curious..

Cleaning the project removes all precompiled binaries that have been created. Then by making the project again creates those from scratch which should contain the proper references for R.

From my understanding, invalidating caches will remove all stored versions of libraries and maybe even some precompiled code and then refetch them when you restart.

*Note: This might not be everything or even what they really do, but I have seen doing each of these get Android Studio back to a working position without changing code from similar situations.

It didn't work. Dumb question thought. I am rebuilding it and i noticed that when I created an activity called ImportActivity, I get the 'R' error. Also I have like 4 activities that i'm creating, don't know if that plays a part.

Did the error messages change at all? If not, I'd probably need to see and poke around the code to be able to help further. The best option would be putting it on GitHub if you can and would want to.

Go figure, seems like when I named the Activity GalleryActivity instead of ImportActivity, it works....

Odd...