java - Gradle 错误 - 无法下载 okhttp.jar 文件 2.7.2

标签 java android firebase gradle okhttp

当我添加 firebase 函数库 (implementation 'com.google.firebase:firebase-functions:16.1.0') 时,android studio(3.1.4) 抛出“Unable to解决 ':app@debug/compileClasspath' 的依赖关系:无法下载 okhttp.jar (com.squareup.okhttp:okhttp:2.7.2)"

我尝试添加“实现文件('libs/okhttp-2.7.2.jar')”但仍然出现同样的错误。

这是我的build.gradle(app)

apply plugin: 'com.android.application'  

android {    
    compileSdkVersion 27  
    buildToolsVersion '27.0.3'  
    defaultConfig {  
        applicationId "com.caliber.mskhan.calibergaming"  
        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(include: ['*.jar'], dir: 'libs')  
    implementation 'com.android.support:appcompat-v7:27.1.1'  
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'  
    testImplementation 'junit:junit:4.12'  
    androidTestImplementation 'com.android.support.test:runner:1.0.2'  
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'  
    implementation 'com.android.support:design:27.1.1'  
    implementation 'de.hdodenhof:circleimageview:2.1.0'  
    implementation 'com.google.android.gms:play-services-maps:15.0.1'  
    implementation 'com.google.android.gms:play-services-location:15.0.1'  
    implementation 'com.google.maps.android:android-maps-utils:0.5'  
    implementation 'com.squareup.picasso:picasso:2.5.2'  
    implementation 'com.github.clans:fab:1.6.4'  
    implementation 'com.github.bumptech.glide:glide:3.7.0'  
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'  
    implementation 'com.android.support:cardview-v7:27.1.1'  
    implementation 'com.android.support:recyclerview-v7:27.1.1'  
    implementation 'com.google.firebase:firebase-auth:16.0.3'  
    implementation 'com.google.firebase:firebase-database:16.0.1'  
    implementation 'com.google.firebase:firebase-storage:16.0.1'  
    implementation 'com.google.firebase:firebase-messaging:17.3.0'  
    implementation 'com.google.firebase:firebase-functions:16.1.0'  
    implementation 'com.google.firebase:firebase-core:16.0.1'  
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.3.1'  
    implementation 'com.android.volley:volley:1.1.0'  
    implementation 'com.karumi:dexter:4.2.0'  

    //implementation files('libs/okhttp-2.7.2.jar')  
}  
apply plugin: 'com.google.gms.google-services'  

这是我的build.gradle(project)

buildscript {

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

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

        classpath 'com.google.gms:google-services:4.0.1'
    }
}

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

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

build errors after gradle sync

最佳答案

Change this 


// 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.1.4'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.0.1'
        classpath 'com.google.firebase:firebase-plugins:1.0.4'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

关于java - Gradle 错误 - 无法下载 okhttp.jar 文件 2.7.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52014868/

相关文章:

java - 如何使用java sqlite连接数据库功能?

java - 使用异常的流程成本

java - 如何使用微调器更改背景图像

Swift - 数据库中的 Firebase 搜索

javascript - Firebase 网站 : upload multiple files to Storage an then download their URLs

javascript 将谷歌云存储桶公开给特定的 URL 或网站

java - 结束结果集和声明

android - 如何隐藏状态栏而不是 ActionBar?

java - 如何计算索引json android的值

java - 从位于另一个类中的一个类访问变量