Frank Palmasani
Frank Palmasani

Reputation: 185

Android AppCompatActivity errors on Gradle Clean

I'll start off by saying that I am aware that this is a somewhat known bug brought up on StackOverflow before, but the solutions offered seem to be temporary for me, or only work sometimes.

See: Cannot resolve symbol 'AppCompatActivity' and Can't resolve AppCompatActivity...

Fixes suggest by these threads offered me temporary fixes that seem to be undone the moment I clean the project before pushing to Github (for the Udacity Nanodegree program).

Has there been a fix that I just can't seem to find online? Again, keep in mind, changing the version to xx.x.+, syncing, xx.x.x, sync again, only seems to work temporarily. Same with Invalidating the caches and restarting. The error returns upon a project/gradle clean.

enter image description here

enter image description here

****Update: This is what my build.gradle looks like:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.example.frank.myappportfolio"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'
}

**** Update: It seems that when I do a Gradle Clean the error comes up but when I Rebuild the project completely the error goes away. Any idea why?

Upvotes: 0

Views: 167

Answers (3)

bohbian
bohbian

Reputation: 901

I have tried clean & Invalidate Cache but couldn't solve the issue.

Problem solved after:

  1. open build.gradle(Module:app)
  2. check compileSdkVersion (my case is "compileSdkVersion 26")
  3. go to the line after "dependencies {"
  4. add/modify "implementation com.android.support:appcompat-v7:26.x.x "
  5. the suitable version will be suggested by AS (click on the yellow light bulb icon) change the number to the one suggested by AS
  6. open the MainActivity java file, import the class manually "import android.support.v7.app.AppCompatActivity;" or click on AppCompatActivity and press Alt+Enter to auto-import.

Upvotes: 0

Nicola Gallazzi
Nicola Gallazzi

Reputation: 8705

After updating Android studio to version 2.3

I've updated appcompat library from version 25.0.1 to 25.1.0

In gradle:

com.android.support:appcompat-v7:25.0.1 (old)

com.android.support:appcompat-v7:25.1.0 (new)

Everything works well now

Upvotes: 1

user6698888
user6698888

Reputation:

Try to clean the android studio's cache, go to the File->Invalidate Caches/Restart

Upvotes: 1

Related Questions