How can I resolve "cannot resolve symbol 'R'" in Android Studio 4.1 relating to a com.google.android.material resource ID?

Viewed 511

I recently upgraded to Android Studio 4.1. Now every so often, AS decides that it doesn't know what 'R' is, and in particular only on a specific resource ID: com.google.android.material.R.id.snackbar_text

I think I remember reading somewhere that these resource IDs have been changed to no longer be declared 'final', but I'm not clear on why or if this would cause this problem.

Invalidating cache and restart "fixes" this for a while, but then it comes back. All types of clean, rebuild project, etc. have no effect.

I am using this resource to dynamically get the TextView associated with the Snackbar in order to change the gravity of where it shows onscreen, but only in certain cases (i.e. I don't want to change the gravity in the XML definition).

How can I stop this from happening?

2 Answers

Try using only R.id.snackbar_text in place of com.google.android.material.R.id.snackbar_text.

Related