TelemetryDeck / FlutterSDK

Flutter SDK for TelemetryDeck, a privacy-conscious analytics service for apps and websites.
https://telemetrydeck.com/
MIT License
3 stars 2 forks source link

Calling .stop() crashes the app #16

Closed liri2006 closed 1 month ago

liri2006 commented 1 month ago

App crashes after trying to call .stop() method.

Steps to reproduce:

await Telemetrydecksdk.start(TelemetryManagerConfiguration(
          appID: Settings.telemetryDeck_appId,
          testMode: Settings.telemetryDeck_isTesting,
          debug: kDebugMode,
        ));
await Telemetrydecksdk.stop();

Log:

E/AndroidRuntime( 9550): FATAL EXCEPTION: DefaultDispatcher-worker-1
E/AndroidRuntime( 9550): Process: com.****.***, PID: 9550
E/AndroidRuntime( 9550): java.lang.IllegalStateException: Method removeObserver must be called on the main thread
E/AndroidRuntime( 9550):    at androidx.lifecycle.LifecycleRegistry.enforceMainThreadIfNeeded(LifecycleRegistry.kt:296)
E/AndroidRuntime( 9550):    at androidx.lifecycle.LifecycleRegistry.removeObserver(LifecycleRegistry.kt:213)
E/AndroidRuntime( 9550):    at com.telemetrydeck.sdk.SessionProvider.stop(SessionProvider.kt:21)
E/AndroidRuntime( 9550):    at com.telemetrydeck.sdk.TelemetryManager$Companion.stop(TelemetryManager.kt:191)
E/AndroidRuntime( 9550):    at com.telemetrydeck.telemetrydecksdk.TelemetrydecksdkPlugin$nativeStop$1.invokeSuspend(TelemetrydecksdkPlugin.kt:55)
E/AndroidRuntime( 9550):    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
E/AndroidRuntime( 9550):    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
E/AndroidRuntime( 9550):    at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
E/AndroidRuntime( 9550):    at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
E/AndroidRuntime( 9550):    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
E/AndroidRuntime( 9550):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
E/AndroidRuntime( 9550):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
E/AndroidRuntime( 9550):    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
E/AndroidRuntime( 9550):    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@a6a20d4, Dispatchers.IO]
I/Process ( 9550): Sending signal. PID: 9550 SIG: 9
kkostov commented 1 month ago

Hi @liri2006, thank you for reporting this!

Indeed, start() and stop() currently require to be called from the main loop. Version 0.5.1 of the Flutter SDK has been published in order to correct the problem. Could you update and retry?

liri2006 commented 1 month ago

@kkostov After update everything works as expected, thank you for the quick fix!