Cannot resolve symbol 'AppCompatActivity'
If the soft methods via gradle file / "Invalidate caches" and the other IDE tools do not work, use the hard way:
- Exit Android Studio
- Navigate in your project to the
.idea
folder - Just Rename the
libraries
folder - Restart Android Studio. It should now recreate the
libraries
folder and work again.
This worked for me on
Android Studio 3.1.2
Build #AI-173.4720617, built on April 13, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-38-generic
Shahbaz Ali confirmed, it works also on
Android Studio 3.1.3
Build #AI-173.4819257, built on June 4, 2018
JRE: 1.8.0_152-release-1024-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.13.0-38-generic
moujib confirmed, it works on Android Studio 3.2.1
A little addition to other answers here, for anyone having the same error while using the right lib version and the right class.
When I upgraded to
appcompat-v7:22.1.0
In which ActionBarActivity
is deprecated and empty and AppCompatActivty
is the way to go, due to some glitch in Android Studio, It didn't quite pick up on version change.
i.e. Even though Gradle ran without errors, the IDE itself kept saying
Cannot resolve symbol 'AppCompatActivity'
(and it also wasn't available through the Ctrl+N
search)
I looked into the .idea/libraries
folder and noticed there's no appropriate metafile for the new version of the lib.
So, using the old-reliable File->Invalidate Caches/Restart did the trick. Always try this when you feel something is magically wrong with Android Studio. And then Disable offline mode and sync.
Today (22 April) you can use the new AppCompatActivity
released with the support libraries v 22.1.0.
Just change your dependency :
compile "com.android.support:appcompat-v7:22.1.0"
Here you can find more info about this new class.