2

I installed Android Studio 2.1.3, and successfully created a new project (just call it ProA), it runs well in AVD. That time I had just only downloaded the SDK platform android-24. I created that project with the Minimum SDK API 14. Actually , I didn't download android-14 at that time.
Then later I downloaded android-14, android-15,android-21,android-23, tried to create a new project (call it ProB), but many errors occurred there.

  1. The MainActivity's superclass is AppCompatActivity , but the error is Cannot solve symbol 'AppCompatActivity'.

  2. There is a red line under the @Override tag over the onCreate() method, saying that Method does not override a method from its superclass

  3. In onCreate() method ,the setContentView(R.layout.activity_main) code snippet shows Cannot resolve symbol 'R'.

  4. The Messages window has a error message saying
    A problem occurred configuring project ':app'.
    Could not download support-compat.aar(com.android.support:-compat:24.2.0): No cached version available for offline mode

the overall picture is like this: the overall error image(click to see)

the content of app\src\build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.example.zhangsir.aftervpn"
        minSdkVersion 14
        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.2.0'
}

the content of gradle\build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

the screenshot of the standalone sdk manager (click to see)


modified at 2016 Aug,27

I have downloaded all the Android SDK Build-tools:Android SDK Build-tools


What can I do to solve this problem?

PlusInfosys
  • 3,416
  • 1
  • 19
  • 33
Julian20151006
  • 191
  • 6
  • 12

6 Answers6

1

go to File >Invalidate Caches & Restart -> Invalidate & Restart

Update

download Android SDK Build-tools 24.0.1

Umar Ata
  • 4,170
  • 3
  • 23
  • 35
  • I did as you said , when it is indexing , it looks OK, but when the indexing is over , the problems are still there. – Julian20151006 Aug 24 '16 at 13:55
  • can you share your app build.gradle in question please – Umar Ata Aug 24 '16 at 13:56
  • I have shared the build.gradle – Julian20151006 Aug 24 '16 at 14:31
  • take a screenshot of your standalone sdk manager and share it. gradle is correct – Umar Ata Aug 24 '16 at 17:20
  • Now the foundmental error is that when I change the dependencies in build.gradle to 24.1.0 or 24.1.1, it works well; when I change the version from 24.1.0 or 24.1.1 to version 24.2.0 and rebuild the project , the Messages Gradle Build window always shows **`Could not download support-compat.aar (com.android.support:support-compat:24.2.0): No cached version available for offline mode`** . But in the **Android\android-studio-sdk\extras\android\m2repository\com\a‌​ndroid\support\appco‌​mpat-v7** directory, I do have 24.2.0 there. – Julian20151006 Aug 27 '16 at 00:40
  • I have downloaded almost all the Android SDK Build-tools, except the preview version 25.2. [click to see](http://i.stack.imgur.com/KB6HQ.png).Is that the reason? – Julian20151006 Aug 27 '16 at 00:49
0

Sometimes, It gets these errors, most of the time we use sync Project if it didn't hover mouse to

Build >Clean Project >Rebuild Project 

If this also, didn't fixed the problem then you might have done something wrong in gradle. You can update gradle if none of these works..

And One more thing I just saw in your question API 14 is not supported by AppCompactActivity so, you must extend Activity for that. AppCompactActivity supports from API 15. For more information see this

Community
  • 1
  • 1
Queendevelopers
  • 183
  • 3
  • 20
0

Try re-downloading the Android Support Repository from the Sdk manager.

Also update the Android Sdk, Platform-tools, Build Tools, Google Support Library to the Latest version.

Saini
  • 734
  • 3
  • 8
  • You are right! But I didn't do that , I just modified the app\src\build.gradle file, and chang the dependencies from compile 'com.android.support:appcompat-v7:24.2.0' to compile 'com.android.support:appcompat-v7:24.1.1' , and Build->Clean Project, Build->Rebuild Project , it's OK now – Julian20151006 Aug 25 '16 at 09:18
  • that's nice. but always try to use the latest version of the appcompact library. – Saini Aug 26 '16 at 17:13
  • I did want to use the latest version of appcompact library, and the version 24.2.0 is choosed by Android Studio by default. But that always arouses error. If I change it to 24.1.0 or 24.1.1, that is OK. I checked the **Android\android-studio-sdk\extras\android\m2repository\com\android\support\appcompat-v7** directory, and found I did have 24.1.0 , 24.1.1 , 24.2.0 there. I don't know why 24.1.0 and 24.1.1 is OK while 24.2.0 arouses error – Julian20151006 Aug 27 '16 at 00:26
  • Now the foundmental error is that when I change the version from 24.1.0 or 24.1.1 to version 24.2.0 in the build.gradle file and rebuild the project , the Messages Gradle Build window always shows **`Could not download support-compat.aar (com.android.support:support-compat:24.2.0): No cached version available for offline mode`** . But in the **Android\android-studio-sdk\extras\android\m2repository\com\a‌​ndroid\support\appco‌​mpat-v7** directory, I do have 24.2.0 there. – Julian20151006 Aug 27 '16 at 00:38
0

Problem solved!
this Messages window in this picture click to see
says Could not download support-compat.aar (com.android.support-compat:24.2.0): No cached version available for offline mode
So I checked the first project which is OK, compare the app\src\build.gradle files in the two projects. the OK one's dependencies is like this:

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

while the error one's dependencies is like this:

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

So I modified the error one's dependencies, then Build->Clean Project, Build->Rebuild Project , it's OK now!

The basic reason is that my network is not available to google's server, many things cannot be downloaded.

Julian20151006
  • 191
  • 6
  • 12
0

If your Android Studio showing that cannot resolve symbol AppCompatActivity or cannot resolve symbol R then you can do one simple thing which is SYNC GRADLE. Click Here for the purpose of demonstration, you can watch it.

Subhojit Halder
  • 145
  • 3
  • 7
0

Simple Solution Here:

If your Android Studio showing that cannot resolve symbol AppCompatActivity or cannot resolve symbol R then you can do one simple thing which is SYNC GRADLE.
"Tools" -> "Android" -> "Sync Project with Gradle Files"
Click Here for the purpose of demonstration, you can watch it.

Subhojit Halder
  • 145
  • 3
  • 7