Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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


}
like image 631
Manish Singla Avatar asked Jan 20 '16 08:01

Manish Singla


People also ask

How do I use OkHttp on Android?

OkHttp Query Parameters ExampleBuilder urlBuilder = HttpUrl. parse("https://httpbin.org/get).newBuilder(); urlBuilder. addQueryParameter("website", "www.journaldev.com"); urlBuilder. addQueryParameter("tutorials", "android"); String url = urlBuilder.

How do I create an OkHttp client?

Customize Your Client With newBuilder() You can customize a shared OkHttpClient instance with newBuilder. This builds a client that shares the same connection pool, thread pools, and configuration. Use the builder methods to add configuration to the derived client for a specific purpose.


1 Answers

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

like image 156
Rohit5k2 Avatar answered Sep 22 '22 05:09

Rohit5k2