Android studio "Cannot resolved symbol AppCompatActivity"

Viewed 238

When I open my old Android Project (it is working normally), It gives AppCompatActivity error.

After that I created a new project but it gives the same error.

enter image description here

This is my default grandle ; enter image description here

I tried to change sdk version, change dependecies, invalidate caches, clean project..

I could not find a solution.

2 Answers

Check if in yout gradle.properties file you have this :

android.useAndroidX=true
android.enableJetifier=true

If is there, what I'm missing in your gradle file is the buildToolsVersion add this below the compileSdkVersion

buildToolsVersion "29.0.2"

Then repeat the steps you followed mentioned in your question.

You are trying to use AndroidX but seems like it doesn't have the library, so you can simply try to migrate to AndroidX, go to:

Refactor -> Migrate to AndroidX ... -> Migrate

Migrate to AndroidX

But if you don't want to migrate to AndroidX, remove the import statement and then let Android Studio import it for you.

  1. Remove the import statement:

    import androidx.appcompat.app.AppCompatActivity;

  2. Focus your pointer on the red lined AppCompatActivity and press Alt+Enter and Android Studio will automatically import it for you.

AppCompatActivity red lined

Related