2
votes

when i new a project error above occur i use android studio 3.0 gradle 4.1 thsi is error:

Error:Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0. Open File
Show Details

Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0. Open File
Show Details

Error:Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0. Open File
Show Details

Error:Unable to resolve dependency for ':app@stagingUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:26.1.0. Open File
Show Details

when i click show details the fllowing is:

Could not resolve com.android.support:appcompat-v7:26.1.0. Required by: project :app

Could not resolve com.android.support:appcompat-v7:26.1.0. Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0-beta2/appcompat-v7-26.1.0.pom'. Could not HEAD 'https://dl.google.com/dl/android/maven2/com/android/support/appcompat-v7/26.1.0/appcompat-v7-26.1.0.pom'. Connect to dl.google.com:443 [dl.google.com/74.125.237.0] failed: Connection timed out: connect Connection timed out: connect

3

3 Answers

2
votes

After much research and headache... Go to File\Settings\Gradle. Deselect the "Offline work" box. Now you can connect and download any necessary or missing dependencies.

1
votes

Since Android 3.0, Android libraries can be directly downloaded with the Google's Maven repository (https://developer.android.com/studio/build/dependencies.html#google-maven).

So in your top-level build.gradle file you can use :

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/'
    }
}

And you can declare a android library like (in app/build.gradle) :

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

For other libraries (not in Google's repo) you can add jcenter() as a repository.

And since Android Gradle Plugin 3.0, configuration compile is deprecated and replaced by implementation (see https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html#new_configurations).

0
votes

I tried everything like uncheck Offline gradle, distributionUrl etc.

But adding this in end of build.gradle file solved my problem -

repositories {
    flatDir {
        dirs 'libs'
    }
}