Retrofit - Unable to find acceptable protocols. isFallback=false

Viewed 1643

I have bellow class for connect to an 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();
    }
}

But get me bellow error:

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]

And my library versions is:

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

I see a lot of questions in stackoverflow and test them but not work I don't need to downgrade the targetSdkVersion and my libraries, what can I do?

0 Answers
Related