Reputation: 155
I have a problem with android studio.
I have added the .jar file of okhttp from this link : https://github.com/square/okhttp to my libs directory on my android studio. and when I try to add this line : compile 'com.squareup.okhttp3:okhttp:3.2.0' in the dependencies in build.gradle(Module:app), after trying to syncing it I get error 28, 13. Actually after researching I found out that I can't compile anything in dependencies and sync it remember that I have checked my "android SDK build tool" is installed.
hear is the whole of my code in build.gradle(app) directory:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.kasra.stormy"
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'], )
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/okhttp-3.2.0.jar')
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
I'll be very glad and thankful if someone help me fix this problem.
Thank you very much:)
Upvotes: 14
Views: 31741
Reputation: 51
Just Replace the dependencies with folowng dependencies and they will work for sure.(100%). if in future this issue comes again then go to https://square.github.io/okhttp/ and update your dependencies with latest one
//define any required ok http without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
//define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
Upvotes: 2
Reputation: 69
You will not need this
compile 'com.squareup.okhttp3:okhttp:3.2.0'
rather you will need
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
As of today the 30th of September 2020 Check https://square.github.io/okhttp/ for documentation
Upvotes: -1
Reputation: 5136
It may help someone. In my case after update com.squareup.okhttp3
to the latest version, I got this error in Android Java libaray. Then I update the Java version to 1.8 which solved my problem.
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
Upvotes: 9
Reputation: 1
Check your code in app.gradle
apply plugin: 'com.android.application'
repositories {
jcenter()}
OR
make your compile okhttp to offline mode, next you uncheck offline mode in setting -> gradle. and try it again
Upvotes: 0
Reputation: 51
you should change the build.gradle(app): use
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
instead of
compile 'com.squareup.okhttp3:okhttp:3.2.0'
or just follow the guide as mentioned here.
Upvotes: 5
Reputation: 1
I solved my problem by editing my build.gradle as below:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':library')
//compile('com.squareup.okhttp3:okhttp:+') {
// exclude group: 'org.json'
//}
//replaced as below:
compile 'com.squareup.okhttp3:okhttp:3.9.1'
}
Upvotes: 0
Reputation: 191894
Either your internet is bad and you can't download that file from JCenter, or you are just missing a repositories
section in your gradle file.
apply plugin: 'com.android.application'
repositories {
jcenter()
}
Also, if you are going to be compiling using gradle instead of a JAR file, then delete the file libs/okhttp-3.2.0.jar
and remove the line that says compile files('libs/okhttp-3.2.0.jar')
.
It is also worth mentioning that you don't need any lines that start with compile files('libs/
because compile fileTree(dir: 'libs', include: ['*.jar'], )
already includes all JAR files within the libs/
folder.
Upvotes: 11