How to fix Expected Android API level 21+ but was 19 in Android

后端 未结 11 1763
甜味超标
甜味超标 2020-12-10 01:06

In my application i want get data from server, for get connect to server i used Retrofit, OkHttp.
But when running application, show me

11条回答
  •  隐瞒了意图╮
    2020-12-10 02:04

    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.

提交回复
热议问题