Open In App

Different Ways to fix Cannot resolve symbol ‘AppCompatActivity’ in Android Studio

When you create a project and extends activity AppCompatActivity, sometimes you must have observed Android Studio throws an error that is:

Cannot resolve symbol ‘AppCompatActivity’

and this error doesn’t go away easily. In this article, we are going to cover topics: why there is a need to solve this error and five different ways to get rid of this error.



Why There is a Need To Solve “Cannot resolve symbol ‘AppCompatActivity'”?

When you rename the application package name this error pops up. The import statement turns gray and says there’s no package for support.v7.app. Even after upgrading to appcompat-v7:22.1.0, in which AppCompatActivty (To get the most out of the Android Support Library that is, to get the latest features supported across the highest number of devices, we need AppCompatActivity) is added, the problem doesn’t go away. So we need to try the following methods to fix this problem in Android Studio.

How To Solve “Cannot resolve symbol ‘AppCompatActivity'”?

Method 1

Method 2

Navigate to File > Invalidate Caches/Restart and then disable offline mode and sync.



Method 3

Step 1: Delete the .idea folder. For .idea folder navigate to YourProject > app > .idea

Step 2: Close and reopen the project

Step 3: File > Sync Project With Gradle Files

Method 4

Method 5

If you have added AndroidX support in Gradle.properties file (that is android.useAndroidX=true and android.enableJetifier=true and if you are using gradle version greater than 3.2),the conventional Appcompat dependency (implementation ‘com.android.support:appcompat-v7:27.1.1’) Replace this dependency with: implementation ‘androidx.appcompat:appcompat:1.1.0’. Moreover, change the AppCompatActivity import in your class file from this:

import android.support.v7.app.AppCompatActivity

to this

import androidx.appcompat.app.AppCompatActivity

Article Tags :