Gradle can't resolve any of my dependencies

1.7k views Asked by At

For some reason gradle can't resolve any of my dependencies. This is an example:

Module:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
        applicationId "app.simplelogin"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:24.2.1'
    compile 'com.squareup.okhttp3:okhttp:3.0.1'
    testCompile 'junit:junit:4.12'
}

Project:

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

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

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

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

When I try to sync or build, I get the following error:

Failed to resolve: com.squareup.okhttp3:okhttp:3.0.1

I get this same error message with every dependency I try to add - anyone know why?

1

There are 1 answers

0
Vampire On

You probably have switched on offline mode in the Gradle tool window of Android Studio. Switch off offline mode and it should work if you have internet connection.