6

I am getting these errors:-

Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:27.0.0.

Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test:runner:1.0.1.

Error:Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve junit:junit:4.12.

Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support.test.espresso:espresso-core:3.0.1.

  1. I have tried many methods but, it is not syncing gradle.
  2. I have tried GRADLE OFFLINE METHOD TOO, BUT THAT ALSO DIDN'T WORK.
  3. I have tried adding GOOGLE MAVEN REPO REPOSITORY BUT THAT DIDN'T WORK.
  4. I have tried all these methods listed here :- Failed to resolve: com.android.support:cardview-v7:26.0.0 android

screenshots where the sync is stuck

SYNC STUCK AT THIS 1

SYNC STUCK AT THIS 2

SYNC STUCK AT THIS 3

SYNC STUCK AT THIS 4

I am new to android studio plz omit mistakes.

Application build.gradle file :

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.example.firstapp.myapplication"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

Application build.gradle file

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

    buildscript {

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


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

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

    task clean(type: Delete) {
        delete rootProject.buildDir
    }
iamvinitk
  • 165
  • 3
  • 15
  • 1
    can you include your **project** build.gradle? not the app build.gradle – ישו אוהב אותך Nov 02 '17 at 11:06
  • i have edited my post, plz help. AND I HAVE ADDED PROJECT BUILD.GRADLE. –  Nov 04 '17 at 07:08
  • Forget about 27, use 26.0.2. – Maki Nov 05 '17 at 04:10
  • i have tried, 26.0.2 too, but its also not working, FIRST GRADLE SYNC STARTS THEN IT STUCKS AT DOWNLOADING THEN AFTER APPROX 10-15MIN LATER, ITS SHOWS THE SAME ERROR. –  Nov 05 '17 at 05:04
  • which version of android studio ? 3.0 or 3.0.1 ? I was getting errors , updated and created new project. worked fine. – Anirban Nov 24 '17 at 07:06
  • Hi, I have the same problem and the only solution I found was removing the testImplementation completly from the gradle files. Did you find another solution? – Sascha Effert May 02 '18 at 12:22

2 Answers2

4

I think that you are missing the Google maven repo.

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

You have the full document here.

Kevin Robatel
  • 8,025
  • 3
  • 44
  • 57
  • If I'm not mistaken, v7 is published on jcenter() so maybe he doesn't actually need to include the google's maven repo. – Joaquim Ley Nov 02 '17 at 10:47
  • I have already included the Google maven repo. but still, i am getting the same error –  Nov 02 '17 at 10:50
  • Have you tried my answer Vipin? – Joaquim Ley Nov 02 '17 at 10:55
  • It didn't work. –  Nov 04 '17 at 07:10
  • Any update @VipinSaini ? I am facing same issue. May be it is proxy issue. – AkshayT Nov 09 '17 at 06:59
  • I have literally tried everything that is on stackoverflow, and at last i noticed one thing, when you will sync your project with *OFFLINE WORK* it will show the same error because the dependencies we are using are all latest versions which are not present in ANDROID SUPPORT REPOSITORY V47(WHICH IS LATEST), and when you will sync project *ONLINE* it will not be able to download dependencies, so instead of searching about the error, search about this. I am also working on it. Kindly post the solution if you find one. –  Nov 09 '17 at 07:19
  • He should actually be using the repo declaration `google()`. – Sakiboy Nov 11 '17 at 21:50
  • @AkshayTaru it is showing unable to resolve dependencies because gradle is not able to download the required dependencies from jcenter, and google's maven repo. It is happening because WHEN YOU SYNC A PROJECT FIRST TIME, AFTER THE INSTALLATION OF ANDROID STUDIO, **JDK ASKS FOR FIREWALL ACCESS** and in your case android studio didn't ask for that, so the solution is just give the firewall access to JDK, I INSTALLED WINDOW 8.1 & WHEN I SYNCED PROJECT IT ASKED FOR FIREWALL ACCES, AND GRADLE SYNCED AUTOMATICALLY. –  Nov 12 '17 at 12:28
  • Or just simply reinstall android studio completely after disabling the antivirus program. –  Nov 12 '17 at 20:32
  • @VipinSaini I agree on SDK asking for firewall access. Because when I install the Studio, it did not asked me for JDK firewall acess popup this time. Usually it asks. – AkshayT Nov 13 '17 at 04:49
  • 2
    bro, it does not ask for any sdk firewall access okay all you have to do is, open your firewall (disable antivirus if it is not letting you open it) then in the inbound rules, add two new rules for java.exe in your c:/programfiles/android/androidstudio/jre/bin/java.exe, 1 for TCP and another for UDP. then restart pc enable antivirus. It will work. Now i am running it on windows 7 like before, but this time i disabled antivirus for first project build, YOU ONLY HAVE TO DISABLE ANTIVIRUS FOR FIRST TIME, try it, it will work. –  Nov 13 '17 at 06:04
  • @user8662258 your suggestion worked! i disabled avast's web shield in mac, and it compiled ! – Sri Krishna Mar 17 '18 at 05:36
0

Change your compile 'com.android.support:appcompat-v7:26.1.0'

To this

implementation 'com.android.support:support-compat:27.0.0'

You'll need the gradle version 3.0.0 to use implementation, on your project level build.gradle you should change

buildscript {
    repositories {
        ...
        // You need to add the following repository to download the
        // new plugin.
        google()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
    }
}
Joaquim Ley
  • 4,038
  • 2
  • 24
  • 42
  • i am on gradel version 4.1, Tt came default when i installed ANDROID STUDIO V 3.0, **I HAVE EDITED THE POST PLZ SEE AGAIN** –  Nov 04 '17 at 07:09
  • use implementation 'com.android.support:appcompat-v7:24.2.1' – Kshama Singh Aug 14 '19 at 05:48