Gradle无法解析任何依赖项

时间:2016-12-19 23:48:35

标签: android gradle android-studio-2.0

由于某种原因,gradle无法解析我的任何依赖项。这是一个例子:

模块:

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

项目:

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
}

当我尝试同步或构建时,出现以下错误:

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

我在尝试添加的每个依赖项中都收到同样的错误消息 - 有人知道为什么吗?

1 个答案:

答案 0 :(得分:1)

您可能已在Android Studio的Gradle工具窗口中启用了离线模式。关闭离线模式,如果您有互联网连接,它应该可以工作。