0

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?

Community
  • 1
  • 1
Frank Palmasani
  • 185
  • 2
  • 13
  • can you show your gradle.build file? –  Aug 17 '16 at 12:27
  • @Frank Palmasani, add this in app level build gradle dependency `//compile 'com.android.support:appcompat-v7:24.1.1' compile 'com.android.support:appcompat-v7:23.1.1'` and comment if you adding `compile 'com.android.support:support-v4:23.4.0'`. – Sandeep Devhare Aug 17 '16 at 12:49
  • @Sandeep_Devhare Won't I have to target an older SdkVersion to compile v7:23.1.1 or am I misunderstanding your suggestion? – Frank Palmasani Aug 18 '16 at 00:33
  • @JemoMgebrishvili I added it. Does it offer any insight? – Frank Palmasani Aug 18 '16 at 00:38
  • 1
    @Frank Palmasani, Just right click your project and select **Show in Explorer** options and do remove whole .gradle folder. Now, goto **File>Invalidate Cache/Restart** I hope it would solve your problem. – Sandeep Devhare Aug 19 '16 at 04:48
  • @Sandeep_Devhare thanks for the suggestion. That works initially. Once I "clean" the project it causes the error to return. But rebuilding the project causes the error to go away. Seems like cleaning causes something important to go away... – Frank Palmasani Aug 19 '16 at 04:58
  • @Frank Palmasani, Please up vote to my comment if you solve this error. – Sandeep Devhare Aug 19 '16 at 06:45

3 Answers3

1

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

  • @Jemo_Mgebrishvili this works as a fix so i can get going again but a clean invalidates any fix this offers; as soon as I do a gradle clean the problem returns. Any idea why? – Frank Palmasani Aug 19 '16 at 18:42
1

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

Nicola Gallazzi
  • 7,897
  • 6
  • 45
  • 64
0

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.
bohbian
  • 861
  • 6
  • 5