Andrew
Andrew

Reputation: 2157

Retrofit okhttp doesn't send any request

At my logcat I have such lines during server call:

Rejecting re-init on previously-failed class java.lang.Class<okhttp3.internal.platform.ConscryptPlatform$platformTrustManager$2>: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/conscrypt/ConscryptHostnameVerifier;


Caused by: java.lang.ClassNotFoundException: Didn't find class "org.conscrypt.ConscryptHostnameVerifier" on path: DexPathList[[zip file "/data/app/package-JHk9QBF7PSIufoXeKqbmNA==/base.apk"],nativeLibraryDirectories=[/data/app/package-JHk9QBF7PSIufoXeKqbmNA==/lib/x86, /system/lib, /system/vendor/lib]]

After some time I can see such message:

okhttp.OkHttpClient: <-- HTTP FAILED: java.net.SocketTimeoutException: timeout

And I checked that internet works well on my device. App doesn't crashes but I can't send any request. For example everything was working well during all this week, and right now smth damaged :( How to fix this error?

UPDATE

My gradle app file:

buildscript {
    ext.kotlin_version = '1.3.71'
    repositories { jcenter() }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.72"
        classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
    }
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'
apply plugin: 'com.google.gms.google-services'


android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "package"
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 87 
        versionName "1.0.0"
        testInstrumentationRunner "android.support.APICallRequests.runner.AndroidJUnitRunner"
    }
    buildTypes {
        debug {
            buildConfigField "String", "API_URL", 'url'
        }
        release {
            buildConfigField "String", "API_URL", 'url'
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }


    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation files('libs/mail.jar')
    implementation 'com.jakewharton.timber:timber:4.7.1'
    implementation 'org.apache.commons:commons-io:1.3.2'

    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    testImplementation 'junit:junit:4.13'


    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'


    // Retrofit
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'
    implementation 'org.jsoup:jsoup:1.13.1'


    implementation 'us.belka:androidtoggleswitch:1.2.2'
    implementation 'com.github.droidbond:LoadingButton:0.1.5'


    implementation 'io.github.tonnyl:whatsnew:0.1.1'
    implementation 'com.github.GrenderG:Toasty:1.3.1'
    implementation 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'

    implementation 'com.daimajia.swipelayout:library:1.2.0@aar'

    implementation 'androidx.browser:browser:1.2.0'

    implementation 'com.google.firebase:firebase-analytics:17.4.2'
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.google.firebase:firebase-messaging:20.2.0'
    implementation 'com.google.firebase:firebase-core:17.4.2'


    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.72'
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0" // JVM dependency
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.72'


    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
}

Upvotes: 2

Views: 4415

Answers (2)

Jesse Wilson
Jesse Wilson

Reputation: 40623

OkHttp attempts to detect with TLS implementation you want, and Conscrypt is one option, though it isn't the default. It looks like OkHttp is crashing because it thinks you want Conscrypt but don't have it available.

Add this line to your dependencies:

implementation 'com.squareup.okhttp3:okhttp:4.7.2'

Then you might get a more useful stacktrace. You really want to post the stacktrace that has the Platform class in it. It should be the first one that prints.

Upvotes: 3

SkypeDogg
SkypeDogg

Reputation: 1040

Looks like OkHttp need something like this: implementation 'org.conscrypt:conscrypt-android:2.4.0'. I'm not sure if it's newest version, but according to Github it is.

Upvotes: 5

Related Questions