Home > OS >  Play Services Locatio v21.0.0 - cannot be cast to ResolvableApiException
Play Services Locatio v21.0.0 - cannot be cast to ResolvableApiException

Time:11-02

I updated Google Play Services Location from

implementation "com.google.android.gms:play-services-location:20.0.0"

to

implementation "com.google.android.gms:play-services-location:21.0.0"

and now the following code doesn't work to enable location on the device:

    LocationServices.getSettingsClient(activity)
        .checkLocationSettings(settingsBuilder.build())
        .addOnCompleteListener { task ->
            try {
                task.getResult(ApiException::class.java)
            } catch (ex: ApiException) {
                when (ex.statusCode) {
                    LocationSettingsStatusCodes.RESOLUTION_REQUIRED -> try {
                        val resolvableApiException =
                            ex as ResolvableApiException

Error

java.lang.ClassCastException: com.google.android.gms.common.api.ApiException cannot be cast to com.google.android.gms.common.api.ResolvableApiException

How to fix it?

CodePudding user response:

If you don't necessarily need 21.0.0 I would suggest using the 20.0.0, as noted in release notes for it.

Warning: This release of play-services-location (v21.0.0) has a known issue that can break SettingsClient APIs. We strongly recommend avoiding this version.

It's a breaking change/thing on Googles part - Issue tracker

  • Related