I’ve just tried to use Android Studio. I’ve created blank project and tried to create Activity
which extends AppCompatActivity
. Unfortunalty Android Studio «says» that it
Cannot 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 use ActionBarActivity
. What am I doing wrong?
asked Mar 22, 2015 at 21:09
4
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.
answered Jun 7, 2015 at 21:26
Ivan BartsovIvan Bartsov
19.4k7 gold badges58 silver badges58 bronze badges
10
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
answered May 2, 2018 at 7:24
DBX12DBX12
2,0411 gold badge15 silver badges25 bronze badges
2
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.
answered Apr 21, 2015 at 22:40
Gabriele MariottiGabriele Mariotti
308k92 gold badges846 silver badges822 bronze badges
1
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.
answered Aug 1, 2018 at 5:30
Abdul MateenAbdul Mateen
1,1091 gold badge13 silver badges21 bronze badges
3
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.
answered Apr 6, 2017 at 19:28
1
Check for typos too, i wasted my whole day looking for solutions when i had actually typed AppCompactActivity instead of AppCompatActivity
answered Aug 8, 2015 at 11:15
0
Cannot resolve symbol AppCompatActivity Issue.
Do the Simple Step to resolve the problem.
i) Exit the Android studio.
ii) Go to your project directory.
iii) Find the .idea folder in your project directory.
iv) Delete .idea folder.
v) Restart your android studio.
vi) The Issue Will be resolved.
answered Oct 16, 2018 at 7:31
1
When you add AndroidX support in Gradle.properties file e.g.
android.useAndroidX=true
android.enableJetifier=true
If you are using Gradle version greater than 3.2, the conventional Appcompat dependancy e.g.
implementation 'com.android.support:appcompat-v7:27.1.1
wont work.
Replace this dependancy 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;
Done
answered Apr 29, 2020 at 18:00
1
I got the Cannot resolve symbol
error for AppCompatActivity and many other classes & methods after updating Android Studio from 2.2.3 to 2.3, updating Android Gradle plugin to 2.3.0, and updating Gradle to 3.3.
File -> Invalidate Caches / Restart
did not resolve the issue.
Preferences -> Build, Execution, Deployment -> Gradle
showed Use local gradle distribution
selected with Gradle home: /Applications/Android Studio.app/Contents/gradle/gradle-2.14.1 and a warning displayed saying the gradle location was incorrect.
Resolved issue by selecting Use default gradle wrapper (recommended)
.
Probably just pointing to the new local distribution location would also work.
answered Mar 2, 2017 at 23:53
jk7jk7
1,9301 gold badge22 silver badges31 bronze badges
0
Try this. In Android Studio, after putting the dependency in build.gradle.
Go to Build —> Clean Project.
It worked for me.
answered Sep 23, 2015 at 21:05
0
Thats really insane, i tried everything, synced with Gradle files, invalidated and restarted android studio. Still the problem persisted. Last resort was deleting .idea/libraries folder and it worked as charm.
answered Sep 10, 2018 at 7:43
0
You can use new AppCompatActivity appcompat-v7:22.1.+
Just add this to your gradle:
compile ‘com.android.support:appcompat-v7:22.1.1’
answered Apr 27, 2015 at 6:28
For me the issue resolved when i updated the appcompact v7 to latest..
compile ‘com.android.support:appcompat-v7:25.3.0’
Hope it helps…:)
answered Mar 28, 2017 at 11:56
Nihas NizarNihas Nizar
6198 silver badges15 bronze badges
So my collegue pushed their local.properties
which broke everything. I copied my sdk path from another app and did:
File -> Sync Project with Gradle Files
answered Mar 18, 2018 at 1:38
Seabass77Seabass77
1875 silver badges13 bronze badges
0
I was getting this same problem with Android SDK 23, while developing on a Mac OS X Yosemite Machine. It turned out that I did not have Java SDK 7.
Once I installed Java SDK 7 and pointed the SDK from with the Android Studio to the new SDK, everything worked for me.
Here are the steps that I followed:
1) Shutdown Android SDK
2) Install Java SDK for Mac OS X from http://www.oracle.com/technetwork/java/javase/downloads/index.html
3) Start the Android SDK and point the SDK for this project to the new 1.7 Java SDK by going to File -> Project Structure -> JDK Location
4) Restart Android Studio
Hope this help
answered Sep 6, 2015 at 23:24
none of below solved my issue
- Restart Android
- File >> Synch Project with Gradle Files
- Build >> Clean Project
- Build >> Rebuild Project
- File >> Invalidate Caches / Restart
Instead, I solved it by updating the version of appcompat & design dependencies to the recent version
To do so: go to build.grade (Module:app) >> dependencies section and then hit ALT + ENTER on both appcompat & design dependencies then select the shown version in my case it’s 24.2.1 as shown in the picture
answered Jul 24, 2018 at 12:50
ZainZain
35.9k7 gold badges55 silver badges82 bronze badges
Remember to press Alt+Enter or add the import.
import android.support.v7.app.AppCompatActivity;
answered Sep 3, 2016 at 0:20
SuragchSuragch
476k306 gold badges1359 silver badges1385 bronze badges
I updated my Gradle 2.3.3 to 4.4 and got an error on AppCompatActivity and also Cardview. I tried with clean project and rebuild project. It won’t work, then I go to Project Folder -> .idea -> create backup of libraries folder and remove it -> then Rebuild Project that solved my issue.
answered Aug 17, 2018 at 12:15
Lets get going step by step: first clean project by using
Build->Clean
if this doesn’t helps then use your second step
File>Invalidate Caches/Restart…
But the real problem begins when all the above options doesn’t works so use your ultimate solution is to close project and go to project location directory and delete
.idea
You can open your project now again.
answered Nov 2, 2018 at 11:55
0
After upgrading to the latest support library, I had to upgrade to the latest Android studio (beta) version and gradle version before the IDE recognized AppCompatActivity again (invalidating caches and restart did not do the trick)
answered Mar 21, 2016 at 8:52
CiskeCiske
2,61628 silver badges31 bronze badges
Add this dependency in project build .gradle.
Follow the example below.
dependencies {
compile 'com.android.support:appcompat-v7:22.1.0'
}
Pang
9,481146 gold badges81 silver badges122 bronze badges
answered Jun 30, 2017 at 6:14
1
Easist Way
- Open app level
build.gradle
and remove appcompact-v7 dependency & Sync. - Add dependency again & Sync.
Error gone!
Before
After
answered Nov 22, 2018 at 11:43
Khemraj SharmaKhemraj Sharma
56.6k26 gold badges201 silver badges210 bronze badges
I solved it adding:
import androidx.appcompat.app.AppCompatActivity;
in the «import» zone of the main .java file. It worked for me.
Hope it helps!
Zain
35.9k7 gold badges55 silver badges82 bronze badges
answered Dec 9, 2019 at 19:42
RorroRorro
1,2171 gold badge11 silver badges17 bronze badges
0
You Have to just Do some change in your Gradle App File by adding some dependency
compile «com.android.support:appcompat-v7:XX:YY:ZZ»
while XX:YY:ZZ is the version code that you are using in your gradle file, otherwise if you set this version lower or higher than that you are using , then your app will face some problems like it will crash sometimes
answered Mar 22, 2018 at 10:50
Nadeem BhatNadeem Bhat
1,0227 silver badges10 bronze badges
i just update my android studio from 2.3.2 to 3.1.2 version. and this error occurs.
i clean project, rebuild project, invalidate cache/restart but nothing works.
i resolve this error by updating appcompat library from
compile ‘com.android.support:appcompat-v7:23.4.0’
to
compile ‘com.android.support:appcompat-v7:25.1.1’
in app build.gradle file.
answered May 3, 2018 at 4:59
If Invalidating caches not helps, just close the project then re-open it. Steps:
- File > Close Project
- Remove the project out of the starting project list
- Close Android Studio
- Open Android Studio
- Open existed Project with this project
answered Sep 24, 2018 at 22:00
This happens because of one the following reasons:
- You do not have the SDK API installed (this was my problem)
- Your project/Android Studio doesn’t know where the needed files are
- Your project references an outdated compile version that does not support AppCompatActivity
- There is a typo
Possible solutions:
-
Check your .gradle file to make sure you’re not referencing an outdated version. AppCompatActivity was added in version 25.1.0 and belongs to Maven artifact com.android.support:appcompat-v7:28.0.0-alpha1, so do not use any version earlier than this. In your build.gradle (Module: app) file you should have the dependency listed:
dependencies {
compile ‘com.android.support:appcompat-v7:25.1.0’
}You may be using a different version, but just make sure you have listed the
dependency. -
Open the SDK manager and download every API 7 or newer. If you were missing the needed API it will fix that issue, and downloading all the newer API’s can save you some hassle later on as well.
- Check for typos in your import statement. Make sure it doesn’t say “AppCompactActivity” instead of “AppCompatActivity”.
- Resync your project (File >Sync project with Gradle files)
- Rebuild your project (Build >rebuild)
- Clean your project (Build >clean project)
- Close and restart Android Studio
- Update Android Studio
- Regenerate your libraries folder – In Android Studio, view your files in project view. Find the folder YourProjectName >.idea >libraries. Rename the folder to “libraries_delete_me”. Close and reopen Android Studio. Open your project again and the libraries folder should be regenerated with all of the files; you can now delete the “libraries_delete_me” folder.
answered May 7, 2019 at 13:18
For me, the issue resolved when I updated the Gradle build version. Don’t know why?
answered Aug 26, 2015 at 17:46
Srikar ReddySrikar Reddy
3,6004 gold badges35 silver badges56 bronze badges
I’ll tell you how did i solved this problem in eclipse.
Download zip file from this link.https://github.com/dandar3/android-support-v7-appcompat then extract this file,open project, in lib folder you will see one jar file named «android-support-v7-appcompat» , add this jar file into your project. Thats it.
answered Jan 27, 2016 at 12:05
Däñish ShärmàDäñish Shärmà
2,8912 gold badges25 silver badges43 bronze badges
This can might be in the version difference in the app level gradle check it once and then re-build
answered Feb 17, 2017 at 15:02
KamalKamal
2352 silver badges3 bronze badges
Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article
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
- 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.
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
- 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.
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
Last Updated :
09 Nov, 2021
Like Article
Save Article
Hey @Daneyl, try this method:
Go to your build.gradle file and in your dependencies find the appcompat one, it will be something like compile com.android.support:appcompat-v7:XX.X.X
Change it to compile com.android.support:appcompat-v7:XX.X.+
. Then you need to sync the project with gradle.
As for your second issue of style parent setting, I want you to be more clear by giving some code example.
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 didnt 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 wasnt available through the Ctrl+N
search)
I looked into the .idea/libraries
folder and noticed theres 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.
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
android – Cannot resolve symbol AppCompatActivity
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.
Related posts on android :
- android – Kotlin: Whats does return@ mean?
- android cannot display PDF (name.pdf is of invalid format)
- android – Kotlin: why would you want to convert Int.toString?
- android – AlertDialog setButton was deprecated
- android – Programmatically Restart a React Native App
- android – File.createTempFile() VS new File()
- Kotlin-allopen for android
- How to import Action Bar Sherlock? android studio
When does this type of error occur?
When you download a new Android Studio or update Android Studio usually the ‘Symbol ‘AppCompatActivity’ issue cannot be resolved, this type of error occurs.
Also, when you import a new project, this type of error is occurring.
Sometimes this type of error occurs because of dependencies in Android Studio.
You can add dependency directly, also add dependency file by clicking on the given link by a mouse hover over error.
When you click on ‘more options’ here you can directly add the dependency.
How to fix the ‘Symbol AppCompatActivity’ error in Android Studio?
Step by step procedure is given for such a solution.
Step: 1
Hover arrow over error.
Step: 2
Now the suggestion box will open.
Here you will see the link ‘add a dependency on androidx.appcompat:appcompat’ or click on more actions.
step: 3
When you click on more options, here you will also see the option Add dependency to androidx.appcompat:app mmpsy:appcompat.
This method automatically detected dependency and downloads the expected files from the internet.
It takes some time to download the required file.