首页 > 解决方案 > 改造 okhttp 不发送任何请求

问题描述

在我的 logcat 中,我在服务器调用期间有这样的行:

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]]

一段时间后,我可以看到这样的消息:

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

我检查了互联网在我的设备上运行良好。应用程序不会崩溃,但我无法发送任何请求。例如,这周一切都运行良好,现在smth损坏了:(如何解决这个错误?

更新

我的毕业应用程序文件:

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

标签: androidokhttp

解决方案


看起来OkHttp需要这样的东西:implementation 'org.conscrypt:conscrypt-android:2.4.0'. 我不确定它是否是最新版本,但根据 Github 是。


推荐阅读