OkHttpClient fails on Android

1,572 views
Skip to first unread message

Simon Martyr

unread,
Mar 14, 2016, 9:03:00 AM3/14/16
to RoboVM
I've been using Retrofit 2.0 to do web services. This all works on iOS. 
However when I try to run the same web services on the Android application I get this error:

java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/OkHttpClient;

relating to this line: 

private static OkHttpClient.Builder httpClient = new okhttp3.OkHttpClient.Builder().readTimeout(60, TimeUnit.SECONDS).connectTimeout(60, TimeUnit.SECONDS);



here is my core gradle : 

buildscript {
    repositories
{
        mavenCentral
()
   
}
}

plugins
{
    id
"me.tatarka.retrolambda" version "3.2.2"
}
apply
plugin: 'java'

version 'unspecified'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral
()
}

dependencies
{
    compile
group: 'net.engio', name: 'mbassador', version: '1.2.0'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'org.roboguice:roboguice:2.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
    compile 'commons-io:commons-io:+'
}


What strikes me as odd is in the error message is the "Lokhttp3"  why is there a L? 

any help would be great. 

Simon Martyr

unread,
Mar 14, 2016, 11:07:55 AM3/14/16
to RoboVM
Update: 

I tried adjusting the dependencies and this worked... but I don't understand why?


dependencies {
    compile
group: 'net.engio', name: 'mbassador', version: '1.2.0'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'org.roboguice:roboguice:2.0'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.squareup.retrofit2:retrofit:+'
    compile 'com.squareup.retrofit2:converter-gson:+'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'commons-io:commons-io:+'
}


So I added okhttp3 separately. This resolved the original problem, however retrofit then started to complain as well as converter-gson. Hence why I tried the + versions to get the current snapshots. This has now got android working... 
But shouldn't have the original configuration have worked?



Reply all
Reply to author
Forward
0 new messages