cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
551 stars 681 forks source link

[HEALTH] App crashes on checking permissions on Android with API lower than 34 #1032

Closed oleksii-melnychenko-pwrcd closed 2 months ago

oleksii-melnychenko-pwrcd commented 2 months ago

Device / Emulator and OS

Describe the bug

When testing example app for the health plugin, the application crashes when when pressing Authenticate button.

To Reproduce

  1. Clone plugin repo
  2. flutter pub get & flutter run
  3. Press Authenticate button and agree to all permissions

Expected behavior

The app to function as on the Android devices with api higher than 33 (>=34)

Actual behavior

App crashes with the following errors:

E/AndroidRuntime( 4962): FATAL EXCEPTION: main E/AndroidRuntime( 4962): Process: cachet.plugins.example_app, PID: 4962 E/AndroidRuntime( 4962): kotlin.UninitializedPropertyAccessException: lateinit property healthConnectClient has not been initialized E/AndroidRuntime( 4962): at cachet.plugins.health.HealthPlugin$hasPermissions$1.invokeSuspend(HealthPlugin.kt:578) E/AndroidRuntime( 4962): at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) E/AndroidRuntime( 4962): at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108) E/AndroidRuntime( 4962): at android.os.Handler.handleCallback(Handler.java:942) E/AndroidRuntime( 4962): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime( 4962): at android.os.Looper.loopOnce(Looper.java:201) E/AndroidRuntime( 4962): at android.os.Looper.loop(Looper.java:288) E/AndroidRuntime( 4962): at android.app.ActivityThread.main(ActivityThread.java:7872) E/AndroidRuntime( 4962): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 4962): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) E/AndroidRuntime( 4962): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) E/AndroidRuntime( 4962): Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@b21a94f, Dispatchers.Main] D/EGL_emulation( 4962): app_time_stats: avg=1833.67ms min=30.87ms max=3636.47ms count=2 I/Process ( 4962): Sending signal. PID: 4962 SIG: 9 Lost connection to device. the Dart compiler exited unexpectedly.

Flutter doctor

[✓] Flutter (Channel stable, 3.24.1, on macOS 14.6.1 23G93 darwin-arm64, locale en-UA) • Flutter version 3.24.1 on channel stable at /Users/lesha/fvm/versions/3.16.0 • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5874a72aa4 (13 days ago), 2024-08-20 16:46:00 -0500 • Engine revision c9b9d5780d • Dart version 3.5.1 • DevTools version 2.37.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/lesha/Library/Android/sdk • Platform android-34, build-tools 33.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2

[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314)

[✓] VS Code (version 1.92.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension can be installed from: 🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (4 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.6.1 23G93 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.6.1 23G93 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 128.0.6613.86

[✓] Network resources • All expected network resources are available.

• No issues found!

oleksii-melnychenko-pwrcd commented 2 months ago

So i was able to tackle this issue. The problem is that only occurs when health connect is not installed on the app which is actually documented in the README. In my defence i cas say that i wasn't expecting the crash as it is. :) Closing this issue

hagen00 commented 2 months ago

I recently upgraded from 9 to 11 and now it crashes on my emulator, API 33 as well with the same error: E/AndroidRuntime(21677): kotlin.UninitializedPropertyAccessException: lateinit property healthConnectClient has not been initialized

Surely this needs fixing? If Health Connect not installed it shouldn't crash the entire app? I'm not sure at this stage if this will happen in production as well, but my most recent update to Huawei was rejected due to a crash and it may be related to this. The update to Google Play is not live yet; I'm hoping that the app doesn't crash on production, if a user doesn't have Health Connect installed.

Seems like a P1 issue to me?