Gradle error - could not download okhttp.jar file 2.7.2

when i added the firebase functions library (implementation 'com.google.firebase:firebase-functions:16.1.0') , android studio(3.1.4) throws "Unable to resolve dependency for ':app@debug/compileClasspath': Could not download okhttp.jar (com.squareup.okhttp:okhttp:2.7.2)"

I tried to add "implementation files('libs/okhttp-2.7.2.jar')" but still got the same error.

this is my 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'  

this is my 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
}

Gradle Could not download okhttp.jar (com.squareup.okhttp3:okhttp , Community Moderator ElectionGradle error - could not download okhttp.jar file 2.7.2What is Gradle in Android Studio?I have some erroes  Running Gradle task 'assembleDebug' Running Gradle task 'assembleDebug' Done 121.6s (!) Exception: Gradle task assembleDebug failed with exit code 1` It seems that the Gradle could not download the .jar file. But when copy the url into browser, it can be downloaded without any difficulty.

Ref: not-able-to-import-com-squareup-okhttp-okhttpclient

Gradle should have a line like this

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

and this is how you import it

import okhttp3.OkHttpClient;

Because OkHttpClient has been moved from package com.squareup.okhttp to okhttp3 in the last version.

More details are here and here

Dependency issue when using OkHttp 2.x and 3.x based releases in , GitHub is home to over 50 million developers working together to host and OkHttp pulls in okio as a dependency and it does not follow the same principle as Not sure if the order in Gradle matters similarly than in Maven. Download okhttp JAR file With dependencies Documentation Source code All Downloads are FREE. Search and download functionalities are using the official Maven repository.

change classpath

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

to

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

its working with me

square/okhttp: Square's meticulous HTTP client for Java , square.github.io/okhttp/ GitHub is home to over 50 million developers working together to host and gradle/wrapper OkHttp is an HTTP client that's efficient by default: This program downloads a URL and prints its contents as a string. (the "License"); you may not use this file except in compliance with the License. okhttp Square’s meticulous HTTP client for Java and Kotlin. com.squareup.okhttp3:okhttp 4.7.2. content_copy

Could not download okhttp.jar (com.squareup.okhttp3:okhttp:3.3.1 , Gradle add implementation 'com.squareup.okhttp3:okhttp:3.3.1' is an error: Unable to Could not download okhttp.jar (com.squareup.okhttp3:okhttp:3.3.1) Open File Show Details. The reason is that okhttp cannot be downloaded. method:. Search and download Java libraries/JAR files inclusive their dependencies. No Maven installation Everything online Free download All Downloads are FREE. Search and download functionalities are using the official Maven repository.

okhttp not found, migrating to Android developer s, when i build my app i am getting the following error. cannot access OkHttpClient class file for com.squareup.okhttp.OkHttpClient i have tried adding dependency so gradle downloads but it fails to find it. implementation It looks like you're trying to load the Dropbox SDK and dependencies directly from jar files yourself. Releases. Here you can find binaries and reference documentation for current and past versions of Gradle. You can find the next release candidate or a bleeding edge nightly build for the release and master branches on their respective pages.

com.squareup.okhttp » okhttp, 2.7.x. 2.7.5 · Central · 424, Feb, 2016. 2.7.4 · Central · 29, Feb, 2016. 2.7.3 · Central · 13, Feb, 2016. 2.7.2 · Central · 64, Jan, 2016. 2.7.1 · Central · 27, Jan, 2016. General data-binding functionality for Jackson: works on core streaming API

Comments
  • try invalidate caches then rebuild the project
  • classpath 'com.google.firebase:firebase-plugins:1.0.4' After adding the above dependency , i tried commenting other dependendencies and synced After the sync was done removed the comments and tried resync issue is resolved for me