Cannot resolve symbol 'AppCompatActivity'
Solution 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.
Solution 2
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
Solution 3
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.
Solution 4
It is too simple.here are the steps you need to follow
1-Exit Android studio.
2-Go to your project directory.
3-Something like this in my case( F>Android->YourProjectName->.idea).
4)-delete libraries folder present in .idea folder.
5)-restart your android studio. and your issue is resolved.
Solution 5
I got it fixed by Going to build.gradle
file and in dependencies the appcompat
one, something like compile 'com.android.support:appcompat-v7:XX.X.X'
Changed it to compile 'com.android.support:appcompat-v7:XX.X.+'
Then click on Sync. All the red squiggly lines should go if everything else in your code is correct.
Related videos on Youtube
Lingviston
Updated on July 08, 2022Comments
-
Lingviston almost 2 years
I've just tried to use Android Studio. I've created blank project and tried to create
Activity
which extendsAppCompatActivity
. Unfortunalty Android Studio "says" that itCannot resolve symbol 'AppCompatActivity'
I have
compile "com.android.support:appcompat-v7:22.0.+"
in dependency list of my "app" module and rebuilt project several times. However I can only useActionBarActivity
. What am I doing wrong?-
ghost talker about 9 yearsare you using right build version? is your sdk is up to date?
-
damson about 9 years@Lingviston you're not using the right version. You should use
com.android.support:appcompat-v7:22.1.0
-
Lingviston about 9 yearsWell there wasn't such version that time.
-
JY2k almost 9 yearsBut now there is and it solves the problem :)
-
-
3c71 almost 9 yearsDoesn't work for me either, each time I upgrade the appcompat, I get into lots of problems.
-
Chris Klingler about 8 yearsFor me this error popped up when updating to Android Studio 2.0 - Clearing the Cache and Restarting as stated above worked perfectly!
-
dsdsdsdsd about 8 yearsI have
compile 'com.android.support:appcompat-v7:23.3.0'
already in mybuild.gradle
... but still getting the error -
behelit over 7 yearshmm I'm using a higher version but still encounter the issue
compile 'com.android.support:appcompat-v7:23.1.1'
-
fWd82 almost 7 years+1, OMG this worked for me. :) BTW the
+
sign is for Hey Gradle if any new version of the same release is availible use is for yourself :) . I was usingcom.android.support:appcompat-v7:25.3.1
now this did a trick:com.android.support:appcompat-v7:25.3.+
Though AS giving me warning: Avoid using + in version numbers; can lead to unpredictable and unrepeatable builds (com.android.support:appcompat-v7:25.3.+) -
George over 6 yearsIf it didn't work, try this one, worked for me: stackoverflow.com/a/36641765/3758439
-
haxpor over 6 yearsI use
:22.0.0
and cannot findAppCompatActivity
class. I have to set it at least to22.1.0
. Thanks. -
A-Sharabiani about 6 yearssame in IntelliJ IDE.
-
Hassan Faghihi about 6 yearsi delete gradle/cache, 4.4 & 2.2.x folders, didn't work, i did invalidate and restart in ide didn't worked, i delete .idea and .gradle folder sided in project files, and restart it, it worked just fine
-
Gabriel Ferreira about 6 yearsfor me it only works when I delete the files (.idea/libraries) and re-imported the files
-
Paras Nakum almost 6 yearsIf above solutions do not work then check this stackoverflow.com/questions/34947794/…
-
Jethro almost 6 yearsDoes not work! Delete the Libray folder in like in one a few down. It works for me stackoverflow.com/a/50129167/2121630
-
Admin about 5 yearsTy for the fix! Also, I would like to know if every user here was using the PC version or iOS version of Android Studio. I have some developer friends who never had any of these issues on iOS. I've had tons of issues on PC. Not sure how many times i've tried to clean/rebuild/invalidate cache...
-
Admin about 5 yearsIf you go inside the .idea folder and rename the "libraries" folder to something different, the trick works as well. If something goes terribly wrong, you only have to go back and rename the libraries folder back to it's original name and try something else, rather than try to restore the entire .idea folder.
-
Admin about 5 yearsI would never delete the folder in case something goes terribly wrong. Simply renaming it will suffice. In the worst case scenario, that the libraries folder isn't regenerated, you can go back and restore the "libraries" folder's original name. After everything is known to work, you can then go back and delete the folder you renamed. If your studio is corrupted, it may not regenerate folders - always take caution when deleting files.
-
DBX12 almost 5 yearsShahbaz Ali and I used the Linux version, moujib only commented that this solution works in 3.2.1
-
TechJ over 4 yearsFor me the following worked : stackoverflow.com/a/54415300/5597466
-
NurShomik almost 4 yearsThis fixed it for me.