2016-12-19 41 views
1

由于某些原因,gradle无法解决我的任何依赖关系。这是一个例子: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 

我得到这个相同错误消息与我尝试添加的每个依赖关系 - 任何人都知道为什么?

+0

这是这个的副本,http://stackoverflow.com/questions/34895397/not-able-to-import-com-squareup-okhttp-okhttpclient – aconnelly

+2

@aconnelly:不,它不是。接受的答案是wj1091已经在做什么。 – CommonsWare

+1

您可以发布更多关于您列出的消息点的Gradle控制台输出吗?另外,您的网络是否有不寻常之处(例如,需要使用代理服务器)? – CommonsWare

回答

1

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