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'”?
- Go to your build.gradle(Module:app) file and in the dependencies section the appcompat one, you should see something like compile ‘com.android.support:appcompat-v7:XX.X.X’, change it to compile ‘com.android.support:appcompat-v7:XX.X.+’ or else hit ALT + ENTER on both appcompat & design dependencies then select the shown version.
- Then click on Sync.
Navigate to File > Invalidate Caches/Restart and then disable offline mode and sync.
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
- Exit Android Studio and reopen it.
- Navigate to the .idea folder in your project
- Just Rename the libraries folder
- Restart Android Studio. It should now recreate the libraries folder and work again.
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 dependancy (implementation ‘com.android.support:appcompat-v7:27.1.1’) Replace this dependancy with: implementation ‘androidx.appcompat:appcompat:1.1.0’. Moreover, change the AppCompatActivity import in your class file from this: