In my application i want get data from server, for get connect to server i used Retrofit, OkHttp.
But when running application, show me
Thanks @ https://stackoverflow.com/users/5773044/anupam This code works in Android API 19:
// Note: 3.12.+ to support Android API 19
implementation 'com.squareup.okhttp3:okhttp:3.12.10'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.10'
implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.4'
implementation 'com.squareup.retrofit2:converter-gson:2.6.4'
implementation 'com.squareup.retrofit2:converter-scalars:2.6.4'
testImplementation 'com.squareup.retrofit2:retrofit-mock:2.6.4'
androidTestImplementation 'com.squareup.retrofit2:retrofit-mock:2.6.4'
I was facing the same issue in API level 19 when I added below in build.gradle file.
implementation 'com.squareup.okhttp3:okhttp:3.12.2'
implementation 'com.squareup.okhttp3:logging-interceptor:3.13.1'
Finally, The Below Code helped me to fix that issue:
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.5.0'
Hope this solution works well for all.
Here I solve that problem downgrading this dependencies to this versions
api 'com.squareup.retrofit2:retrofit:2.3.0'
api 'com.squareup.retrofit2:converter-gson:2.3.0'
api 'com.squareup.okhttp3:okhttp:3.8.0'
And adding this code into onCreate of MainActivity
try {
ProviderInstaller.installIfNeeded(this);
} catch (GooglePlayServicesRepairableException e) {
// Indicates that Google Play services is out of date, disabled, etc.
// Prompt the user to install/update/enable Google Play services.
GoogleApiAvailability.getInstance()
.showErrorNotification(this, e.getConnectionStatusCode());
} catch (GooglePlayServicesNotAvailableException e) {
// Indicates a non-recoverable error; the ProviderInstaller is not able
// to install an up-to-date Provider.
}
Downgrade dependencies is neet because newest version need android API 21 or later.
That code above is to android update your security provider to protect against SSL exploits. See https://developer.android.com/training/articles/security-gms-provider.html to know more about it.
OKHTTP just dropped support for Android 4
https://github.com/square/okhttp/issues/4481
You must use an older version or maybe a sperate branch for your app.
See this Medium post from Jessie Wilson for more info: https://medium.com/square-corner-blog/okhttp-3-13-requires-android-5-818bb78d07ce
Android 4.x?
Google’s distribution dashboard shows that ~11% of the devices that visited the Play Store in October 2018 were running Android 4.x. We’ve created a branch, OkHttp 3.12.x, to support these devices. Should we encounter any severe bugs or security problems we’ll backport the fixes and release. We plan to maintain this branch through December 31, 2020.
If you really need TLSv1.2 on Android 4.x, that’s possible! Ankush Gupta has written a thorough guide that explains how to get Google Play Services to do it. Even if you follow this process you should still use OkHttp 3.12.x with Android 4.x devices.
so you can use below code and resolve your problem
implementation ("com.squareup.okhttp3:okhttp:3.12.12"){
force = true //API 19 support
}
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.12'