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 trialJonathan Grieve
Treehouse Moderator 91,253 PointsCannot resolve symbol "R" in Android Project
I understand this is probably a common error in Android but I've been trying to flush this bug out for a couple of days.
I have a few build errors in my project.
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies]
[file path]
Error:(10) No resource identifier found for attribute 'layout_constraintRight_toTopOf' in package 'uk.co.jonniegrieve.newinteractivestory'
[file path]
Error:(10) No resource identifier found for attribute 'layout_constraintRight_toTopOf' in package 'uk.co.jonniegrieve.newinteractivestory'
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
And in my project, where there's any reference to the "R" package an error is returned which pops up as Cannot Resolve Symbol "R"
I've gone to Stack Overflow. I've tried importing variable classes I've tried updating Gradle, cleaning/rebuilding the project I've tried updating the SDK multiple times but the bug won't go away.
Here's the project, https://github.com/jg-digital-media/android-interactive-storyapp
Any ideas what I need to update? Thanking you! :)
1 Answer
Christopher Augg
21,223 PointsJonathan,
I cloned your project and found the following in your activity_story.xml:
app:layout_constraintHorizontal_bias="0.375"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintRight_toTopOf="@+id/storyTextView"
The last line seems to be the issue. I changed the line and added a constraintBottom_toTopOf :
app:layout_constraintBottom_toTopOf="@+id/storyTextView"
app:layout_constraintHorizontal_bias="0.375"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
That allowed it to compile and run once completed. Please let me know if this works for you.
Chris
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsBingo!
I saw the errors about the constraints but I had no idea fixing those would clear the error with the R package.
Any idea why that would confuse Android so much? I don't understand. Thanks :)
Christopher Augg
21,223 PointsChristopher Augg
21,223 PointsHeya. Glad it is working now. I honestly never ran into this issue before but according to Constraint Layout Docs, the list of available constraints within resources are:
Therefore, I think the layout_constraintRight_toTopOf is not in R, and no identifier for it can be found. It looks like constraints need to connect on their respective axis. Hope this helps.
Chris