Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: FusedLocationClient.isLocationServiceEnabled crashes #1366

Open
3 of 8 tasks
greg-tekai-com opened this issue Nov 1, 2023 · 10 comments · May be fixed by #1557 or #1367
Open
3 of 8 tasks

[Bug]: FusedLocationClient.isLocationServiceEnabled crashes #1366

greg-tekai-com opened this issue Nov 1, 2023 · 10 comments · May be fixed by #1557 or #1367
Assignees
Labels
type: enhancement New feature or request

Comments

@greg-tekai-com
Copy link

greg-tekai-com commented Nov 1, 2023

Please check the following before submitting a new issue.

Please select affected platform(s)

  • Android
  • iOS
  • Linux
  • macOS
  • Web
  • Windows

Steps to reproduce

I'm unable to reproduce a disconnect locally, but we have thousands of crash reports with the stack trace captured in the actual results when we get disconnected from play services.

We're pretty sure that the bug is within FusedLocationClient.isLocationServiceEnabled. If the response is not successful, it calls listener.onLocationServiceError(), but doesn't exit, and all other paths from this point are attempting to return a second result which would also crash.

In our case, after returning an error via onLocationServiceError, the method calls response.getResult which throws an exception if the result was not successful as per docs. This exception is not caught and causes the thread to crash.

Interestingly, it's primarily Amazon fire devices (~90%) that get disconnected, but we do see Pixels and Galaxy phones along with some others.

Expected results

If we get disconnected from services, it should simply call result.error once and return.

Actual results

The thread crashes with:

Stack trace

Fatal Exception: com.google.android.gms.tasks.RuntimeExecutionException: com.google.android.gms.common.api.ApiException: 22: API failed to connect while resuming due to an unknown error.
       at com.google.android.gms.tasks.zzw.getResult(com.google.android.gms:play-services-tasks@@18.0.2:3)
       at com.baseflow.geolocator.location.FusedLocationClient.lambda$isLocationServiceEnabled$0(FusedLocationClient.java:142)
       at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.2:1)
       at android.os.Handler.handleCallback(Handler.java:938)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7719)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
       
Caused by com.google.android.gms.common.api.ApiException: 22: API failed to connect while resuming due to an unknown error.
       at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@18.1.0:3)
       at com.google.android.gms.common.api.internal.ApiExceptionMapper.getException(com.google.android.gms:play-services-base@@18.1.0:1)
       at com.google.android.gms.common.api.internal.zag.zad(com.google.android.gms:play-services-base@@18.1.0:1)
       at com.google.android.gms.common.api.internal.zabq.zaE(com.google.android.gms:play-services-base@@18.1.0:1)
       at com.google.android.gms.common.api.internal.zabq.zaD(com.google.android.gms:play-services-base@@18.1.0:2)
       at com.google.android.gms.common.api.internal.zabq.zaw(com.google.android.gms:play-services-base@@18.1.0:6)
       at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(com.google.android.gms:play-services-base@@18.1.0:47)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:223)
       at android.os.HandlerThread.run(HandlerThread.java:67)

Code sample

Code sample
    final isLocationServiceEnabled = await Geolocator.isLocationServiceEnabled();

Screenshots or video

Screenshots or video demonstration

[Upload media here]

Version

10.1.0

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.13.8, on Ubuntu 22.04.3 LTS 5.15.0-86-generic, locale en_CA.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ Android SDK file not found: /media/greg/sdks/android/platforms/android-34/android.jar.
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2022.3)
[✓] Android Studio (version 2022.2)
[✓] VS Code (version unknown)
    ✗ Unable to determine VS Code version.
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.
@TimHoogstrate TimHoogstrate self-assigned this Nov 2, 2023
@TimHoogstrate TimHoogstrate added the type: enhancement New feature or request label Nov 3, 2023
@TimHoogstrate TimHoogstrate linked a pull request Nov 6, 2023 that will close this issue
10 tasks
@AvidanGC
Copy link

E/AndroidRuntime(12981): FATAL EXCEPTION: main
E/AndroidRuntime(12981): Process: io.app.example, PID: 12981
E/AndroidRuntime(12981): java.lang.IncompatibleClassChangeError: Found class com.google.android.gms.location.FusedLocationProviderClient, but interface was expected (declaration of 'com.google.android.gms.location.FusedLocationProviderClient' appears in /data/app/~~8o8e888GaypcD02QVX9q2w==/io.app.example-4ohfhzzJfudc8cAh8t6Ccw==/base.apk)
E/AndroidRuntime(12981): at com.lyokone.location.FlutterLocation.createLocationCallback(FlutterLocation.java:220)
E/AndroidRuntime(12981): at com.lyokone.location.FlutterLocation.changeSettings(FlutterLocation.java:198)
E/AndroidRuntime(12981): at com.lyokone.location.MethodCallHandlerImpl.onChangeSettings(MethodCallHandlerImpl.java:106)
E/AndroidRuntime(12981): at com.lyokone.location.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.java:40)
E/AndroidRuntime(12981): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/AndroidRuntime(12981): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/AndroidRuntime(12981): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/AndroidRuntime(12981): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/AndroidRuntime(12981): at android.os.Handler.handleCallback(Handler.java:942)
E/AndroidRuntime(12981): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(12981): at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(12981): at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(12981): at android.app.ActivityThread.main(ActivityThread.java:8741)
E/AndroidRuntime(12981): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(12981): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime(12981): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
I/Process (12981): Sending signal. PID: 12981 SIG: 9.
need help please, any idea ?

@huvi8161
Copy link

I have the same error, @TimHoogstrate is your PR a solution for this error, do you plan to send it for merge?

@jozefvodicka
Copy link

Still happening...
Is it possible to look into it, test the proposed solution and merge it?

@tentenponce
Copy link

tentenponce commented Apr 22, 2024

hi @greg-tekai-com @TimHoogstrate is there any way to reproduce this? Does the PR has been tested to fix the issue? We have similar reports to this, a little bit different but the same reason which is related to connectivity issues.

Fatal Exception: com.google.android.gms.tasks.RuntimeExecutionException: com.google.android.gms.common.api.b: 20: The connection to Google Play services was lost due to service disconnection. Last reason for disconnect: Timing out service connection.
       at com.google.android.gms.tasks.zzw.getResult(:19)
       at com.baseflow.geolocator.location.FusedLocationClient.lambda$isLocationServiceEnabled$0(FusedLocationClient.java:11)
       at com.google.android.gms.tasks.zzi.run(:21)
       at android.os.Handler.handleCallback(Handler.java:942)
       at android.os.Handler.dispatchMessage(Handler.java:99)
       at android.os.Looper.loopOnce(Looper.java:240)
       at android.os.Looper.loop(Looper.java:351)
       at android.app.ActivityThread.main(ActivityThread.java:8370)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:568)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)

Caused by com.google.android.gms.common.api.b: 20: The connection to Google Play services was lost due to service disconnection. Last reason for disconnect: Timing out service connection.
       at com.google.android.gms.common.api.internal.zaad.zah(zaad.java:108)
       at com.google.android.gms.common.api.internal.zaad.zae(zaad.java:43)
       at com.google.android.gms.common.api.internal.zabq.zaH(zabq.java:14)
       at com.google.android.gms.common.api.internal.zabq.onConnectionSuspended(zabq.java:16)
       at com.google.android.gms.common.api.internal.zabq.zaJ(zabq.java:14)
       at com.google.android.gms.common.api.internal.zabq.zaL(zabq.java:22)
       at com.google.android.gms.common.api.internal.zabq.zap(zabq.java:17)
       at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(GoogleApiManager.java:641)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loopOnce(Looper.java:240)
       at android.os.Looper.loop(Looper.java:351)
       at android.os.HandlerThread.run(HandlerThread.java:67)

@tentenponce
Copy link

attaching here also the similar issue with react native, and with their solution. Actually, its not a solution but just hides the actual error. But since the error is coming from Google itself, what we can do is to wait for them to fix the actual issue.

similar RN issue: Agontuk/react-native-geolocation-service#137
fix: https://github.com/Agontuk/react-native-geolocation-service/pull/147/files

@mofogasy
Copy link

mofogasy commented May 14, 2024

We encounter the same problem when calling Geolocator.isLocationServiceEnabled if the location services are disabled on the device.

E/AndroidRuntime(23245): FATAL EXCEPTION: main
E/AndroidRuntime(23245): Process: xxx, PID: 23245
E/AndroidRuntime(23245): com.google.android.gms.tasks.RuntimeExecutionException: com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED
E/AndroidRuntime(23245): 	at com.google.android.gms.tasks.zzw.getResult(com.google.android.gms:play-services-tasks@@18.0.2:3)
E/AndroidRuntime(23245): 	at com.baseflow.geolocator.location.FusedLocationClient.lambda$isLocationServiceEnabled$0(FusedLocationClient.java:161)
E/AndroidRuntime(23245): 	at com.baseflow.geolocator.location.FusedLocationClient$$ExternalSyntheticLambda0.onComplete(D8$$SyntheticClass:0)
E/AndroidRuntime(23245): 	at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks@@18.0.2:1)
E/AndroidRuntime(23245): 	at android.os.Handler.handleCallback(Handler.java:958)
E/AndroidRuntime(23245): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(23245): 	at android.os.Looper.loopOnce(Looper.java:230)
E/AndroidRuntime(23245): 	at android.os.Looper.loop(Looper.java:319)
E/AndroidRuntime(23245): 	at android.app.ActivityThread.main(ActivityThread.java:8893)
E/AndroidRuntime(23245): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(23245): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
E/AndroidRuntime(23245): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/AndroidRuntime(23245): Caused by: com.google.android.gms.common.api.ResolvableApiException: 6: RESOLUTION_REQUIRED
E/AndroidRuntime(23245): 	at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@18.1.0:2)
E/AndroidRuntime(23245): 	at com.google.android.gms.common.api.internal.TaskUtil.setResultOrApiException(com.google.android.gms:play-services-base@@18.1.0:4)
E/AndroidRuntime(23245): 	at com.google.android.gms.internal.location.zzcq.zzb(com.google.android.gms:play-services-location@@21.0.1:2)
E/AndroidRuntime(23245): 	at com.google.android.gms.internal.location.zzr.zza(com.google.android.gms:play-services-location@@21.0.1:3)
E/AndroidRuntime(23245): 	at com.google.android.gms.internal.location.zzb.onTransact(com.google.android.gms:play-services-location@@21.0.1:3)
E/AndroidRuntime(23245): 	at android.os.Binder.execTransactInternal(Binder.java:1380)
E/AndroidRuntime(23245): 	at android.os.Binder.execTransact(Binder.java:1311)
I/flutter (23245): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (23245): │ PlatformException(LOCATION_SERVICES_DISABLED, Location services are disabled. To receive location updates the location services should be enabled., null, null)
I/flutter (23245): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23245): │ #0   StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
I/flutter (23245): │ #1   MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:334:18)
I/flutter (23245): │ #2   <asynchronous suspension>
I/flutter (23245): │ #3   GeolocatorAndroid.isLocationServiceEnabled.<anonymous closure> (package:geolocator_android/src/geolocator_android.dart:73:13)
I/flutter (23245): │ #4   <asynchronous suspension>
I/flutter (23245): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (23245): │ Error caught in guarded zone
I/flutter (23245): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

@wzslr321
Copy link

wzslr321 commented Aug 7, 2024

I am also encountering it on Android. Is there any work planned regarding resolving that?

@tentenponce tentenponce linked a pull request Aug 17, 2024 that will close this issue
10 tasks
@tentenponce
Copy link

hi @greg-tekai-com , I forcefully replicated the issue by simply intentionally throwing the same error that we're encountering. I managed to successfully add a proper error handling, and was able to handle it on the Flutter side.

For the mean time while waiting for the contributors to review the PR, I forked the library, specifically the geolocator_android, apply the fix and overrides the geolocator_android dependency in our pubspec.yaml.

@kazbek-sultanov-t
Copy link

Is there any update related to this issue?

@martinsinn
Copy link

We have tons of crashes related to this issue. Any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
10 participants