44

After renaming application package name, Android Studio displayed this error can't resolve symbol AppCompatActivity

Things I tried:

  • Clean project
  • Clean Android Studio cache
  • Clean Gradle cache
  • Re-installed IDE
  • File-> Invalidate cache/restart

But nothing really helped. The project build successfully, but I can not use syntax highlighting.

I used com.android.support:appcompat-v7:23.1.1

Screenshots

BaseActivity

Build gradle file

13
  • At first, you should delete the line with "import android.app.Activity", then check your build.gradle file and make sure your imports are well typed/declared.
    – Rob
    Jan 22, 2016 at 13:39
  • Everything is good in buid.gradle file. compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:appcompat-v7:23.1.1' Jan 22, 2016 at 13:41
  • Ok, can you post your gradle file?
    – Rob
    Jan 22, 2016 at 13:43
  • add build.gradle file screen to post Jan 22, 2016 at 13:46
  • Do not post images of test! Jan 22, 2016 at 13:47

35 Answers 35

82

Okay, to anybody who might stumble upon this now, Android Studio is very, very, very weird.

Solution : Go to your build.gradle file and in your dependencies find the appcompat one, something like compile 'com.android.support:appcompat-v7:XX.X.X'

Change it to compile 'com.android.support:appcompat-v7:XX.X.+'

Then click on Sync Now on the top right of the editor. All the red squiggly lines should go if everything else in your code is correct.

Then go back to your build.gradle and change it back to whatever it was and click Sync Now

It should all be fine given that you have the latest version of everything or close to it.

8
  • 5
    wow, I can't believe this solution is actually works. I spent half hour try to solve this. ty.
    – Ryde
    Jun 13, 2016 at 6:46
  • @IgorGanapolsky I do not know, it means the latest version of whatever is the current, some weird Android Studio bug.
    – 4127157
    Dec 28, 2016 at 17:03
  • 3
    I had the same problem and just had to press the "Sync Project with Gradle Files" without making any changes to anything. I think my issue arises from transferring between machines using github repos.
    – musterjunk
    Aug 5, 2017 at 19:16
  • 1
    I had the problem where it said the cannot find symbol but it allowed to build and run... i just had to sync this file again thanks a ton! Nov 1, 2017 at 9:41
  • 1
    I had to replace the entire version with a plus sign, not just the last X Jul 27, 2018 at 13:19
64

Lets get going step by step: first clean project by using

Build->Clean

if this doesn't helps then use your second weapon

File>Invalidate Caches/Restart...

But the real problem begins when all the above options doesn't works so use your ultimate weapon close project and go to project location directory and delete

.idea

You can open your project now again. This worked for me and problem comes most often when you are working with VCS. And this problem is not associated with android component classes but also to the libraries, both shows the same error.

6
  • 7
    Thank you very much, the deleting .idea worked! I spent more than 2 hours with experimenting to solve this problem and fortunately I found your solution. Android Studio 2.3.3 Jul 24, 2017 at 20:31
  • 1
    Thank you, this is the only solution that worked in my case!
    – XIII
    May 6, 2018 at 18:41
  • Thanks! This solved my problem, Android Studio was importing only some packages of support library, weird...
    – rafael
    Aug 3, 2018 at 18:50
  • This didn't work for me. what worked was to add + in my grade dependancy of appcompat, Aug 13, 2018 at 2:13
  • Deleting .idea folder worked for me too, while other solutions didn't Sep 26, 2018 at 10:44
24

I was having the same issue, but when I did Invalidate cache/restart option it worked fine for me.

First try to clear all your build files

Build->Clean

if it doesn't work try this option

File -> Invalidate cache/Restart

1
  • 1
    Perfect! Perfect! Perfect! The right answer and simple. This usually happens when you hop around different projects. Feb 13, 2018 at 14:20
9

If methods like

Clean project

Clean Android Studio cache

Clean Gradle cache

Re-installed IDE

File-> Invalidate cache/restart

do not work. use this method to resolve your issue.

Exit Android Studio

Navigate in your project to the .idea folder

Remove .idea folder

Restart Android Studio.

Thats it.

6

The issue could be import reference, try changing it.

From:

import android.support.v7.app.AppCompatActivity;

To:

import androidx.appcompat.app.AppCompatActivity;
5

For me was enough to go on: - Tools > ANDROID > SYNC PROJECT WITH GRADLE FILES

The first voice

2
  • This solution worked for me. It seems the activity could not find references to the appcompat library
    – William
    Jun 2, 2017 at 8:33
  • This also helped me a lot.Thanks for this suggestion
    – priyanka
    Mar 5, 2018 at 7:32
4

I was having this exact same issue just a couple minutes ago and fixed it by doing a Build > Rebuild Project.

Hope it helps.

0
2

Only removing whole .gradle folder helped me.

1
  • Tried everything above, but this end up worked for me.
    – loveNZ
    May 28, 2018 at 20:39
2

This is what worked for me, strangely enough:

  1. Change implementation 'com.android.support:appcompat-v7:26+' to implementation 'com.android.support:appcompat-v7:26.0.1'
  2. Go to File → Invalidate Caches/Restart
  3. Wait for the Gradle sync to finish on restarting. Once it does you will be prompted to add the Google maven support repository. Click on the corresponding link, and let Gradle resolve the dependencies.
  4. The errors should be gone now

FWIW, in my case the issue occured after moving my Android Studio installation to a new machine and upgrading to AS 3.1.

2

Deleting the ".idea" folder worked for me. As mentioned above by Vikas Kumar

Then I using this to fix the "SDK location error"

1
  • First I clean the project, after remove all .idea folders and finally Invalidate/Restart Jun 3, 2018 at 16:08
2

You got error like

enter image description here

1.First you have to clean project after that same issue got then

2.check library minimum compile "com.android.support:appcompat-v7:22.1.0"

  1. Check library does not use two or more times enter image description here

  2. Remove multiple time usage of library dependency

  3. Clean and Rebuild Project to a got solution
2

I was stuck with this problem and its take me whole day to solve this.Finally i solved this with the following steps

  1. Close your android studio
  2. Go to you project folder and look for .idea folder
  3. Find libraries folder and rename it
  4. Then start your Android studio and open that project again.

Thats it.

0
1

I had the same issue and the following worked for me

File -> Invalidate cache/Restart

There is some kind of caching issue that is happening. If such kind of issue appears try this since most of the time it will work :D

1

i have this problem while using the android studio on ubuntu 16.04 go to File>invalid cache/Restore>Invalidate and Restart that works fine for me

1

Go to your build.gradle file and in your dependencies find the appcompat one, something like compile 'com.android.support:appcompat-v7:25.X.X' Change it to compile 'com.android.support:appcompat-v7:25.3.+' Then click on Sync Now on the top right of the editor. Then go back to your build.gradle and change it back to whatever it was and click Sync Now This worked for me.

1

This working for me, on macOS:

go to, Android Studio -> Preferences -> Appearance & Behavior -> System Settings -> Android SDK -> SDK Platforms And download Android SDK Platform XX and Sources for Android XX. Where XX es the value of compileSdkVersion on your gradle (Module:app)

on Windows the route is: File -> Settings... -> Appearance & Behavior -> System Settings -> Android SDK -> SDK Platforms

1

If all attempts failed (invalidate cache, clean and rebuild, restart,...), close Android Studio (maybe just close the project), run any file manager, go to project folder, find .idea/libraries folder and delete its content (list of xml files). After new start AS or opening project the problem should be resolved.

1

head over to build.gradle(module app)

if you hover your mouse over to com.android.support:appcompat a popup will say new version is available just replace in the existing version number with the new version number press sync now and you are good to go p.s nothing else worked for me on 2 pc's

1

In Android Studio 3.1.2, I have the same issue After renaming application package name. The following worked for me:

Deleting the ".idea" folder, Then File -> Invalidate Caches/Restart.

1

I've noticed that Android Studio 3.1 doesn't pull in the support libraries seamlessly. Here's how to trigger it. Update the support library version to 27.x.x newer version (you can get the new version info by mouse hover over the version number next to implementation under dependencies ) manually in the module's build.gradle file under dependencies. Then re-sync the project. Find the Visual Solution(Image) from this Link

1

This usually happens when you open any old project. Open your Build.gradle (app module) file and update the dependencies to the latest version which you can find in any recently created project or create a new project and copy the dependencies. Sync and then clean your project.

EX: Older versions--> compile 'com.android.support:appcompat-v7:24' Update to latest version--> implementation 'com.android.support:appcompat-v7:28.1.1'

1

If the methods via gradle file / "Invalidate caches" do not work, use this way:

  1. Navigate in your project to the .idea folder
  2. Just Rename the libraries folder
  3. Restart Android Studio. It will recreate the libraries folder and work again.
1

Guys I know this is gonna sound stupid but I only switched my project like I had 2 projects in my system so I opened the other project when it was completely ready I clicked on open to open my actual project and it worked so just try to switch projects and re open it, this should sort out your issue.

1

Easy

  • Open app level build.gradle
  • Remove appcompact-v7 dependency & Sync.
  • Add dependency again & Sync.

Error is no more! :)

Before

before

After

after

1

Close your project using FILE -> CLOSE PROJECT and then Open, worked for me fixed all the issues.

1

I tried deleting the .idea folder, Clean Build, Validate Caches / Restart, changing Build Tools vers... None of them worked for me.

I solved this error with selecting the red underlined codes then pressing Alt+Enter and selecting the Import Class option. It changes the imports to **androidx.core.*******. If you do this to all your red underlined codes your errors should have resolved.

0

I've updated appcompat library from version 25.0.1 to 25.1.0

In gradle:

from: com.android.support:appcompat-v7:25.0.1

to: com.android.support:appcompat-v7:25.1.0

Everything works well now.

0

When all your dependencies and SDK tools are in-line and it still is giving sync error. Add this code in your build.Gradle and sync it:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Also like to point, before doing this I tested all tricks mentioned here. But only this worked for my Android (2.3) - Feb'17 release.

1
  • Yes. Thanks @EnamulHaque I know, I'm yet to upgrade my version. That's Feb'17 Android Studio release version. Hope it helps someone. Feb 12, 2018 at 5:27
0

With the new Release of android studio 3.1.3, you must put this code inside build.gradle.

implementation 'com.android.support:design:23.4.0'
0

Open build.gradle file and in your dependencies and

Change file with

implementation 'androidx.appcompat:appcompat:1.0.0-beta01'

This worked for me..

1
  • Hello and welcome! What does this answer provide that the highest voted one does not already provide? stackoverflow.com/a/36641765/10747134 It seems like most of it was copied and pasted from there as well.
    – user10747134
    Mar 20, 2019 at 15:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.