45

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

m00am
  • 5,910
  • 11
  • 53
  • 69
Raman Branavitski
  • 864
  • 1
  • 9
  • 22

35 Answers35

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.

4127157
  • 1,438
  • 2
  • 15
  • 28
  • 5
    wow, I can't believe this solution is actually works. I spent half hour try to solve this. ty. – Ryde Jun 13 '16 at 06:46
  • @IgorGanapolsky I do not know, it means the latest version of whatever is the current, some weird Android Studio bug. – 4127157 Dec 28 '16 at 17:03
  • if i add compact-v7 in build.gradle showing no resource in ui elements errors before that project in eclipse to studio migrated project now am plan to update with new version in that time we are using Activity now plan for AppCompactActivity with ToolBar and material designing updates and at that time google play services as lib added now how can i add google play services in build.gradle i have so many doubts and confusions from eclipse migrated to studio old project. – Harsha Jan 23 '17 at 11:22
  • @Harsha You need to clean project and rebuild, it should work. – 4127157 Jan 26 '17 at 21:55
  • 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 05 '17 at 19:16
  • @musterjunk That solves the problem for some but in my case it didn't so I found this. – 4127157 Aug 06 '17 at 12:14
  • 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! – Crazy Alien Nov 01 '17 at 09:41
  • 1
    I had to replace the entire version with a plus sign, not just the last X – Impulse The Fox Jul 27 '18 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.

vikas kumar
  • 10,447
  • 2
  • 46
  • 52
  • 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 – Zsivics Sanel Jul 24 '17 at 20:31
  • 1
    Thank you, this is the only solution that worked in my case! – XIII May 06 '18 at 18:41
  • Thanks! This solved my problem, Android Studio was importing only some packages of support library, weird... – rafael Aug 03 '18 at 18:50
  • This didn't work for me. what worked was to add + in my grade dependancy of appcompat, – Dilip Agheda Aug 13 '18 at 02:13
  • Deleting .idea folder worked for me too, while other solutions didn't – Andreas Oikonomou Sep 26 '18 at 10:44
  • This worked for me with the additional step: Upon reopen of the project I still had compilation errors - hovering over the red code marked as unresolved, hitting 'alt+enter' to reapply the imports worked for me. – Kai Nov 03 '18 at 11:15
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

Sushin Pv
  • 1,826
  • 3
  • 22
  • 36
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.

mehmoodnisar125
  • 1,469
  • 18
  • 14
6

The issue could be import reference, try changing it.

From:

import android.support.v7.app.AppCompatActivity;

To:

import androidx.appcompat.app.AppCompatActivity;
CodeSlave
  • 457
  • 6
  • 17
5

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

The first voice

Blasco73
  • 2,980
  • 2
  • 24
  • 30
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.

McSullivan
  • 124
  • 2
  • 13
2

Only removing whole .gradle folder helped me.

Raman Branavitski
  • 864
  • 1
  • 9
  • 22
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.

Glutanimate
  • 1,692
  • 20
  • 21
2

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

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

Omphile
  • 21
  • 4
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
Paras Nakum
  • 238
  • 2
  • 8
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.

Kashinath
  • 194
  • 1
  • 1
  • 8
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

Nauman Shah
  • 342
  • 2
  • 12
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.

Sumit Garai
  • 1,205
  • 8
  • 6
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

fmnavarretem
  • 151
  • 1
  • 4
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.

Petr Daňa
  • 1,263
  • 12
  • 18
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.

Javan
  • 183
  • 2
  • 10
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

Rishav
  • 3,818
  • 1
  • 31
  • 49
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.
Shubham Goel
  • 1,962
  • 17
  • 25
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

Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
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.

EnesKY
  • 21
  • 1
  • 5
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.

Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51
Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64
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.

piet.t
  • 11,718
  • 21
  • 43
  • 52
Rohit Sharma
  • 1,271
  • 5
  • 19
  • 37
  • Yes. Thanks @EnamulHaque I know, I'm yet to upgrade my version. That's Feb'17 Android Studio release version. Hope it helps someone. – Rohit Sharma Feb 12 '18 at 05: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'
Fabulous
  • 2,393
  • 2
  • 20
  • 27
alaa
  • 1
  • 1
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..

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

I had the same issue and it resolved by installing build-tools library.

Masood Anwar
  • 73
  • 10
0

recently I encountered this problem, I used java code and Kotlin in the development of my application. I really spent a lot of time searching for the cause of the problem. I tried everything in this comment but the problem still doesn't go away, and the program can't be run yet.

so the problem I have is about the Kotlin version of the project that doesn't match the version that is in the android studio framework.

when I equate it, the problem disappears and the program runs again. Hope this helps.

enter image description here

arjava
  • 1,719
  • 2
  • 17
  • 21
0

I was having the same issue, but when re-built project it worked fine for me.

Kulwant
  • 35
  • 9
-1

Try first these both solution: 1. File >> Invalidate Caches / Restart and

  1. Change implementation 'com.android.support:appcompat-v7:XX.X.+' to implementation 'com.android.support:appcompat-v7:XX.X.+'

If above both solution doesn't work ,try this it surely work, it work for me even

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) Start your android studio.

-2

This sometimes happens when you import some other projects in your IDE.
In that case try Building your project 2 to 3 times it automatically gets resolved.

For Rebuild you need to follow the following path:

Build-> Rebuild Project

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Navneet
  • 1
  • 1