not able to import com.squareup.okhttp.OkHttpClient;

I am working on android studio and fetching some data from the web. I tried using OkHttpClient and also added jars to my project folder but still i am unable to import it.

It shows can't resolve symbol okhttp. I tried some solution but unable to solve the problem.Here is my build.gradle file

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0"

    defaultConfig {
        applicationId "com.example.app"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }


}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.android.gms:play-services:8.4.0'
 //   compile files('libs/okhttp-3.0.1.jar')
   // compile files('libs/okio-1.6.0.jar')


}

Gradle should have a line like this

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

square - okhttp - OkHttpClient cannot be resolved, Try Removing your import, and just go to this line OkHttpClient client = new OkHttpClient();. move your cursor to OkHttpClient and press  Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Learn more First 25 Users Free


You need to add the following libraries:

compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'

Dependency issue when using OkHttp 2.x and 3.x based releases in , OkHttp pulls in okio as a dependency and it does not follow the same principle OkHttpClient; import okhttp3. to newer versions of okhttp by being able to rely on both major version OkHttpClient(); com.squareup.okhttp. But if you use something that is not in your remote repo you need to download that jar and then run maven install it in local repo which creates a folder in ~/.m2/repository/ – Shashank Nov 5 '16 at 18:27


Let gradle handle download and import for you:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.squareup.okhttp3:okhttp:3.0.1'
}

Using the OkHttp library for HTTP requests - Tutorial, I have an application that i have not needed to update since moving to API v2 in 2017. Due to google cannot access OkHttpClient class file for com.squareup.​okhttp.OkHttpClient not found import com.squareup.picasso.​OkHttpDownloader; If your goal is to provide a way to easily to migrate to newer versions of okhttp by being able to rely on both major version branches, that's not possible with this combination of dependencies. This is not a major issue for us as we migrated to Retrofit 2.0.2 and therefore OkHttp 3.2.0 without eventually not having to depend on both versions


I see you are/were trying to compile with a jar you manually put in your libs folder. Is there a reason for this (such as you need that specific version of the library etc.)? In case you didn't notice, the lines are commented out - that means they will not be processed and thus not added to your application.

Possible solutions:

  1. Uncomment the lines
  2. Try adding this to your dependencies instead:

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

You can add it right under

compile 'com.google.android.gms:play-services:8.4.0'

Source: https://github.com/square/okhttp

Cannot Resolve Symbol OkHttpClient, import com.squareup.okhttp.internal.ws.RealWebSocket; point in the future. */. public static WebSocketCall create(OkHttpClient client, Request request) {. 1,179 artifacts. Note: This artifact was moved to: com.squareup.okhttp3 » okhttp. Atlassian 3rd-P Old (3)


android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'
    useLibrary  'org.apache.http.legacy'
    ...
}

dependencies {
...
compile 'com.squareup.okhttp3:okhttp:3.4.1'

}

And change your import from com.squareup.okhttp.OkHttpClient to

import okhttp3.OkHttpClient;

okhttp not found, migrating to Android developer s, java - square - okhttp - OkHttpClient cannot be resolved -. Get link import android.os.bundle; // cannot resolve symbol 'okhttp3' import  from ..myapp import SomeObject However, this will work only if you are importing TestCase from the package. If you want to directly run python TestCase.py, you would have to mess with your path. This can be done within Python: import sys sys.path.append("..") from myapp import SomeObject though that is generally not recommended.


okhttp-ws/src/main/java/com/squareup/okhttp/ws/WebSocketCall , Requests. * that are already complete cannot be canceled. */ used the shared SSL context, when OkHttp enables ALPN for its SPDY-related. * stuff, it would  I just try to use OkHttp but I have the following issue when I sync my gradle file with Android Studio : Error:Failed to find: com.squareup.okhttp:okhttp:2.4.0 Here is the dependencies part of my


java - square - okhttp - OkHttpClient cannot be resolved -, import com.squareup.okhttp.internal.http. final OkHttpClient client; throw new ProtocolException("cannot write request body after response has been read");. OkHTTP is an open source project designed to be an efficient HTTP client. It supports the SPDY protocol. SPDY is the basis for HTTP 2.0 and allows multiple HTTP requests to be multiplexed over one socket connection. If you are using Maven or Gradle as build system you can simply add a dependency to group ID com.squareup.okhttp, artifactId


OkHttpClient.java - Source,