Retrofit okhttp不发送任何请求

问题描述 投票:0回答:2

在我的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

[我检查了互联网在我的设备上是否运作良好。应用程序不会崩溃,但我无法发送任何请求。例如,在本周的所有时间里,一切都运转良好,现在已经损坏了:(如何解决此错误?

更新

我的gradle应用文件:

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'
}
android okhttp
2个回答
1
投票

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


0
投票

[OkHttp尝试使用所需的TLS实现进行检测,虽然不是默认方法,但Conscrypt是一个选项。 OkHttp似乎崩溃了,因为它认为您需要Conscrypt但不可用。

将此行添加到您的依赖项中:

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

然后您可能会获得更有用的堆栈跟踪。您确实要发布其中包含Platform类的stacktrace。它应该是第一个打印的。

© www.soinside.com 2019 - 2024. All rights reserved.