Android Kotlin - Unresolved reference: AppCompatActivity after updating to 1.5

2.8k views Asked by At

After the update to

'androidx.appcompat:appcompat:1.5.0'

I get unresolved reference

in

class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {

at

AppCompatActivity()

I deleted the old imports which were marked red to see if there will be import suggestions on hover over AppCompatActivity but there is nothing.

I also cleared and rebuilt the project.

How to solve this?

2

There are 2 answers

0
IHateGoogle On BEST ANSWER

The problem was due to older Android Studio version, I didn't get an update notification because there was an issue with the kotlin version.

I uninstalled/reinstalled kotlin plugin, updated Android Studio and then everything worked

0
Adil Hussain On

In my case, neither the androidx.appcompat.app.AppCompatActivity class nor the androidx.appcompat.app package could be resolved because I did not have an explicit dependency in my application's build.gradle file on the appcompat library.

My application was able to resolve the androidx.appcompat.app.AppCompatActivity class previously because one or more of the AndroidX libraries that I was depending on had an explicit dependency on the appcompat library.

However, it seems that recent versions of the AndroidX libraries hide away their dependency on the appcompat library so it's necessary for us to make an explicit androidx.appcompat:appcompat dependency declaration in our applications.