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

时间:2018-08-25 07:05:53

标签: java android firebase gradle okhttp

当我添加firebase函数库(实现'com.google.firebase:firebase-functions:16.1.0')时,android studio(3.1.4)抛出“ 无法解决“: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

3 个答案:

答案 0 :(得分:0)

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
}

答案 1 :(得分:0)

参考:not-able-to-import-com-squareup-okhttp-okhttpclient

Gradle应该有这样的一行

compile 'com.squareup.okhttp3:okhttp:3.0.1'

这就是您导入它的方式

import okhttp3.OkHttpClient;

因为OkHttpClient已从软件包com.squareup.okhttp移至最新版本的okhttp3。

更多详细信息为herehere

答案 2 :(得分:0)

更改类路径

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

classpath 'com.google.gms:google-services:4.2.0'

它与我合作