cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
547 stars 658 forks source link

health 6.0.0 - Android crash when trying to fetch steps #728

Open nugaa opened 1 year ago

nugaa commented 1 year ago

Device / Emulator and OS

Hi devs!

I'm currently facing an issue with the Android version of the app crashing for some users in production. I have tried to reproduce this issue, but I'm not able to do it... I can see the crashes in crashlytics.

98% of the crashes occur in Samsung devices for some reason.

To Reproduce

Try to fetch steps from Google Fit first time.

Expected behaviour

Get steps from Google Fit.

Actual behavior

`Fatal Exception: java.lang.RuntimeException Failure delivering result ResultInfo{who=null, request=1111, result=-1, data=Intent { (has extras) }} to activity {se.formsatsningen/se.formsatsningen.MainActivity}: java.lang.IllegalStateException: Reply already submitted

android.app.ActivityThread.deliverResults (ActivityThread.java:5994)

com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)`

`Caused by java.lang.IllegalStateException Reply already submitted

io.flutter.embedding.engine.dart.DartMessenger$Reply.reply (DartMessenger.java:35) io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success (MethodChannel.java:14) cachet.plugins.health.HealthPlugin.onActivityResult (HealthPlugin.java:35) io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onActivityResult (FlutterEngineConnectionRegistry.java:25) io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onActivityResult (FlutterEngineConnectionRegistry.java:13) io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onActivityResult (FlutterActivityAndFragmentDelegate.java:51) io.flutter.embedding.android.FlutterActivity.onActivityResult (FlutterActivity.java:10) android.app.Activity.dispatchActivityResult (Activity.java:8951)

com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)`

Screenshots

Screenshot 2023-05-30 at 12 22 34

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.10.2, on macOS 13.3.1 22E772610a darwin-x64, locale en-PT) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 14.3) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.2) [✓] Connected device (4 available) [✓] Network resources

• No issues found!

Additional information

This issue only happens on Android devices, iOS users don't experience this.

albint3r commented 1 year ago

I had the same problem. The way I solved it was by logging in with Google at the top level of the App. Once I did this, I accepted all the permissions and was able to read the steps.

As a side note, it took me 2 weeks to solve this problem, but this method helped me finish my work.

chrisvidal commented 1 year ago

Hi @albint3r facing the same issue, can you explain please how you did login with Google at the top level of the App, please? what does this mean exactly? thanks

dynamicpace-admin commented 1 year ago

I've encounter the same issue and fixed it by first checking healthFactory.hasPermissions(healthDataTypes, permissions: permissions) and if I do not have permission I use the requestAuthorization. the requestAuthorization threw the error for me. But as I said I've not seen your code but hopefully its related and you can proceed.

I'm also using samsung device A14

nugaa commented 1 year ago

I've encounter the same issue and fixed it by first checking healthFactory.hasPermissions(healthDataTypes, permissions: permissions) and if I do not have permission I use the requestAuthorization. the requestAuthorization threw the error for me. But as I said I've not seen your code but hopefully its related and you can proceed.

I'm also using samsung device A14

I believe this option will fix the current issue. I will write a feedback as soon as I have one.

Thank you all for your insights on this.

bulgarian-beast commented 11 months ago

Any update?

albint3r commented 11 months ago

Hi @albint3r facing the same issue, can you explain please how you did login with Google at the top level of the App, please? what does this mean exactly? thanks

What I mean by this issue is that your app should already have Google Login in place from the moment the user logs in. When I faced the issue, it was because we were using flavors, and 3 out of 4 did not have Google Login. So, I only asked for the login when they entered the screen where the steps were going to be counted, and this caused conflicts. Once I understood that the login should be the first step, the problem resolved itself.

I'm not sure if you've already tried this, but that's how simple I solved the problem.

albint3r commented 11 months ago

Any update?

What I mean by this issue is that your app should already have Google Login in place from the moment the user logs in. When I faced the issue, it was because we were using flavors, and 3 out of 4 did not have Google Login. So, I only asked for the login when they entered the screen where the steps were going to be counted, and this caused conflicts. Once I understood that the login should be the first step, the problem resolved itself.

I'm not sure if you've already tried this, but that's how simple I solved the problem.