Sơn Phan
Sơn Phan

Reputation: 1170

Cannot resolve class of basic widget in xml

Happen on Android Studio Preview - Arctic Fox (2020.3.1) Beta 4.

enter image description here

I've tried literally everything from multiple questions on SO; Clean Build, Invalidate Caches and Restart, remove root project's .gradle and .idea, remove caches folder in .gradle, even remove and download Android Studio again, you name it.

It's been almost a day and still can't figure it out, please help, this is killing my motivation :(

Upvotes: 6

Views: 3502

Answers (6)

I had the same issue that Android studio can't recognize the xml elements

⛔ Problem

Cannot resolve class layout
Element layout must be declared

✅ Solution

Is the clear the cache of Android Studio

enter image description here

Upvotes: 1

Vladimir Kondenko
Vladimir Kondenko

Reputation: 307

In my case deleting ~/.gradle and invalidating caches did the trick.

Upvotes: 0

Youssef MAHERZI
Youssef MAHERZI

Reputation: 71

I was facing the same problem with an old project written totally in Java. Adding the following dependency in the project gradle file solved the problem.

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"

Upvotes: 5

Georgeous
Georgeous

Reputation: 1

For me updating the kotlin version resolved that.

Upvotes: -1

Sơn Phan
Sơn Phan

Reputation: 1170

I've finally managed to solve this problem myself.

The steps are to remove the current project --> clone the project again from git --> Re-import project and rebuild.

Android Studio is funny sometimes.

Upvotes: 1

Bola Ibrahim
Bola Ibrahim

Reputation: 780

You can use this for imageView

<androidx.appcompat.widget.AppCompatImageView />

instead of

<ImageView />

and for textView use this

<androidx.appcompat.widget.AppCompatTextView />

instead of

<TextView />

Upvotes: 0

Related Questions