Raman Branavitski
Raman Branavitski

Reputation: 894

can't resolve AppCompatActivity

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

Things I tried:

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

Upvotes: 47

Views: 84013

Answers (30)

Kulwant
Kulwant

Reputation: 35

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

Upvotes: 0

CodeSlave
CodeSlave

Reputation: 457

The issue could be import reference, try changing it.

From:

import android.support.v7.app.AppCompatActivity;

To:

import androidx.appcompat.app.AppCompatActivity;

Upvotes: 6

Chhatrasal Singh
Chhatrasal Singh

Reputation: 39

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.

Upvotes: -1

arjava
arjava

Reputation: 1899

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

Upvotes: 0

Masood Anwar
Masood Anwar

Reputation: 73

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

Upvotes: 0

Dhruv Parmar
Dhruv Parmar

Reputation: 39

Open build.gradle file and in your dependencies and

Change file with

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

This worked for me..

Upvotes: 0

EnesKY
EnesKY

Reputation: 21

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.

Upvotes: 1

Mohammad Abraq
Mohammad Abraq

Reputation: 99

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

Upvotes: 1

Khemraj Sharma
Khemraj Sharma

Reputation: 58934

Easy

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

Error is no more! :)

Before

before

After

after

Upvotes: 1

Manish Gidwani
Manish Gidwani

Reputation: 11

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.

Upvotes: 1

Kashinath
Kashinath

Reputation: 370

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.

Upvotes: 2

Shubham Goel
Shubham Goel

Reputation: 2186

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.

Upvotes: 1

Vivek Yadav
Vivek Yadav

Reputation: 11

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'

Upvotes: 1

mehmoodnisar125
mehmoodnisar125

Reputation: 1529

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.

Upvotes: 9

alaa
alaa

Reputation: 1

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'

Upvotes: 0

Paras Nakum
Paras Nakum

Reputation: 230

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

Upvotes: 2

Teja Kummarikuntla
Teja Kummarikuntla

Reputation: 373

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

Upvotes: 1

Javan
Javan

Reputation: 183

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.

Upvotes: 1

Sushin Pv
Sushin Pv

Reputation: 1894

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

Upvotes: 24

Azhar Rasheed
Azhar Rasheed

Reputation: 51

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

Upvotes: 1

Omphile
Omphile

Reputation: 21

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

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

Upvotes: 2

Petr Daňa
Petr Daňa

Reputation: 1293

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.

Upvotes: 1

Navneet
Navneet

Reputation: 1

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

Upvotes: -2

Glutanimate
Glutanimate

Reputation: 1772

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.

Upvotes: 2

fmnavarretem
fmnavarretem

Reputation: 171

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

Upvotes: 1

Rohit Sharma
Rohit Sharma

Reputation: 2669

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.

Upvotes: 0

Sumit Garai
Sumit Garai

Reputation: 1331

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.

Upvotes: 1

user5698605
user5698605

Reputation:

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

Upvotes: 1

Nauman Shah
Nauman Shah

Reputation: 352

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

Upvotes: 1

vikas kumar
vikas kumar

Reputation: 11018

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.

Upvotes: 64

Related Questions