84

I am having this issue in Android studio.

Error:(22, 13) Failed to resolve: com.android.support:appcompat-v7:26.0.0
<a href="install.m2.repo">Install Repository and sync project</a><br><a href="openFile:C:/Users/username/AndroidStudioProjects/ElectroSave/app/build.gradle">Show in File</a><br><a href="open.dependency.in.project.structure">Show in Project Structure dialog</a>

This is my Gradle code:

apply plugin: 'com.android.application'

android {
       compileSdkVersion 26
      buildToolsVersion "25.0.2"
    defaultConfig {
    applicationId "com.example.noelly.myapplication"
    minSdkVersion 19
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
}
   buildTypes {
      release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 
'proguard-rules.pro'




 dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.android.support:appcompat-v7:26.0.0'
}
Zoe
  • 27,060
  • 21
  • 118
  • 148
CyberCat
  • 957
  • 1
  • 7
  • 10
  • 1
    i think there is some issue on android studio update(stable version), but works in android studio 3 canary version.To fix just downgrade your support library repo compile 'com.android.support:cardview-v7:25.3.1' – S J Jul 28 '17 at 11:24
  • Well, did you `Install Repository and sync project`? – OneCricketeer Jul 29 '17 at 14:07
  • 7
    @AndroidGeek The newest versions of the support libraries are at Google Maven repo, which needs setup https://developer.android.com/topic/libraries/support-library/setup.html – OneCricketeer Jul 29 '17 at 14:09

14 Answers14

212

To use support libraries starting from version 26.0.0 you need to add Google's Maven repository to your project's build.gradle file as described here: https://developer.android.com/topic/libraries/support-library/setup.html

allprojects {
        repositories {
            jcenter()
            maven {
                url "https://maven.google.com"
            }
        }
    }

For Android Studio 3.0.0 and above:

allprojects {
        repositories {
            jcenter()
            google()
        }
    }
Dangiras Rackauskas
  • 3,114
  • 1
  • 17
  • 10
  • just make sure you have to add google() under allprojects in buildscript it would have been already added. Thats how it was in my case and I managed to fix it from this answer. – joekevinrayan96 Jan 05 '21 at 03:28
61

Please be noted, we need to add google maven to use support library starting from revision 25.4.0. As in the release note says:

Important: The support libraries are now available through Google's Maven repository. You do not need to download the support repository from the SDK Manager. For more information, see Support Library Setup.

Read more at Support Library Setup.

Play services and Firebase dependencies since version 11.2.0 are also need google maven. Read Some Updates to Apps Using Google Play services and Google APIs Android August 2017 - version 11.2.0 Release note.

So you need to add the google maven to your root build.gradle like this:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

For Gradle build tools plugin version 3.0.0, you can use google() repository (more at Migrate to Android Plugin for Gradle 3.0.0):

allprojects {
    repositories {
        jcenter()
        google()
    }
}

UPDATE:

From Google's Maven repository:

The most recent versions of the following Android libraries are available from Google's Maven repository:

To add them to your build, you need to first include Google's Maven repository in your top-level / root build.gradle file:

allprojects {
    repositories {
        google()

        // If you're using a version of Gradle lower than 4.1, you must instead use:
        // maven {
        //     url 'https://maven.google.com'
        // }
        // An alternative URL is 'https://dl.google.com/dl/android/maven2/'
    }
}

Then add the desired library to your module's dependencies block. For example, the appcompat library looks like this:

dependencies {
    compile 'com.android.support:appcompat-v7:26.1.0'
}

However, if you're trying to use an older version of the above libraries and your dependency fails, then it's not available in the Maven repository and you must instead get the library from the offline repository.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • 5
    `google()` does not exist in `2.3.3` of the Android Plugin for Gradle. It is not from the Android Plugin for Gradle at all. It is from Gradle itself. It exists in Gradle 4.1 and does not exist in Gradle 3.3 -- I am not certain where in there it was added. – CommonsWare Sep 03 '17 at 15:59
  • 1
    This is the completed answer, plus the explanation why google() is missing in older gradle versions – Stoycho Andreev Sep 18 '17 at 20:52
7
  1. Add this in build.gradle(Project:projectname)

    allprojects {
      repositories {
        jcenter()
        maven { url "https://maven.google.com" }
      }
    }
    
  2. Add this in build.gradle(Module:app)

    dependencies {
      compile 'com.android.support:appcompat-v7:26.1.0'
    }
    
Hamid Rouhani
  • 2,309
  • 2
  • 31
  • 45
Chinki Sai
  • 251
  • 4
  • 5
5

If you already use jitpack.io or any repository. You can add google repository like this:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        maven { url "https://maven.google.com" }
    }
}
Mehmet Hanoğlu
  • 2,942
  • 1
  • 13
  • 19
3

you forgot to add add alpha1 in module area

compile 'com.android.support:appcompat-v7:26.0.0-alpha1'

use maven repository in project area that's it

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}
BakaWaii
  • 6,732
  • 4
  • 29
  • 41
3

change

compile 'com.android.support:appcompat-v7:26.0'

to

`compile 'com.android.support:appcompat-v7:26.+'`

worked for me fine.

1

If you are using Android Studio 3.0, add the Google maven repository as shown below:

allprojects {
  repositories {
    jcenter()
    google()
 }
}
1

enter image description hereI was facing the same issue but I switched 26.0.0-beta1 dependencies to 26.1.0 and it's working now.

Buzz
  • 25
  • 7
  • I'd recommend including the actual text needed to fix it, instead of a screenshot. That way we can make sure search engines pick it up, plus it's a lot cleaner. – Taegost Jan 02 '18 at 19:13
1

My issue got resolved with the help of following steps:

For gradle 3.0.0 and above version

  1. add google() below jcenter()
  2. Change the compileSdkVersion to 26 and buildToolsVersion to 26.0.2
  3. Change to gradle-4.2.1-all.zip in the gradle_wrapper.properties file
Monika Moon
  • 188
  • 3
  • 9
1

Adding the below content in the main gradle has solved the problem for me:

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
        flatDir {
            dirs 'libs'
        }
    }
rajkabbur
  • 187
  • 3
0

Go to SDK path: SDK\extras\android\m2repository\com\android\support\appcompat-v7 to see correct dependency name, then change name if your dependency is alpha version:

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

to :

dependencies {
  compile fileTree(dir: 'libs', include: ['*.jar'])
  compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
}
Ehsan Jelodar
  • 1,544
  • 19
  • 25
0

File -> Project Structure -> Modules (app) -> Open Dependencies Tab -> Remove all then use + to add from the proposed list.

Zoe
  • 27,060
  • 21
  • 118
  • 148
TiyebM
  • 2,684
  • 3
  • 40
  • 66
0

Can you control internet access ? If you dont have internet access, your ide doesnt download package then you encountered this problem.

MahmutKarali
  • 339
  • 4
  • 8
0

1 - in build.gradle change my supportLibVersion to 26.0.0

2 - in app/build.gradle use :

implementation "com.android.support:appcompat v7:${rootProject.ext.supportLibVersion}"

3 - cd android

4 - ./gradlew clean

5 - ./gradlew assembleRelease