Модификация - невозможно найти приемлемые протоколы. isFallback = ложь - PullRequest
0 голосов
/ 05 апреля 2020

У меня есть нижеприведенный класс для подключения к API (https):

@Module
public class RemoteAPIDataModule {
    @Provides
    Gson provideGson() {
        return new GsonBuilder().create();
    }

    @Provides
    PublicApi providePublicApi(Retrofit retrofit) {
        return retrofit.create(PublicApi.class);
    }

    @Provides
    Retrofit provideRetrofit(Gson gson) {

        ConnectionSpec spec = new
                ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
                .tlsVersions(TlsVersion.TLS_1_2)
                .cipherSuites(
                        CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
                        CipherSuite.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
                        CipherSuite.TLS_DHE_RSA_WITH_AES_128_GCM_SHA256)
                .build();
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
                .connectTimeout(60, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .connectionSpecs(Collections.singletonList(spec))
                .build();
        return new Retrofit.Builder()
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addConverterFactory(ScalarsConverterFactory.create())
                .baseUrl(API_BASE_URL)
                .build();
    }
}

Но выведите меня ниже:

java.net.UnknownServiceException: Unable to find acceptable protocols. isFallback=false, modes=[ConnectionSpec(cipherSuites=[TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256], tlsVersions=[TLS_1_2], supportsTlsExtensions=true)], supported protocols=[SSLv3, TLSv1]

И у меня есть версии библиотеки:

compileSdkVersion 29
    buildToolsVersion '29.0.2'
    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 29

        renderscriptTargetApi 18
 .....
 implementation 'com.squareup.retrofit2:retrofit:2.7.1'
 implementation 'com.squareup.okhttp3:okhttp:3.14.4'
 .....

Я вижу много вопросов в stackoverflow и тестирую их, но они не работают. Мне не нужно понижать версию targetSdkVersion и моих библиотек, что я могу сделать?

...