Skip to content

❗ Crash when using Autocapture on version 1.19.3 #234

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

Closed
bezmian opened this issue Jan 22, 2025 · 2 comments
Closed

❗ Crash when using Autocapture on version 1.19.3 #234

bezmian opened this issue Jan 22, 2025 · 2 comments

Comments

@bezmian
Copy link

bezmian commented Jan 22, 2025

Expected Behavior

App should not crash.

Current Behavior

App is crashing with the following stacktrace:

java.lang.RuntimeException: Can't create handler inside thread Thread[DefaultDispatcher-worker-1,5,main] that has not called Looper.prepare()
	at android.os.Handler.<init>(Handler.java:227)
	at android.os.Handler.<init>(Handler.java:129)
	at android.view.GestureDetector$GestureHandler.<init>(GestureDetector.java:310)
	at android.view.GestureDetector.<init>(GestureDetector.java:425)
	at android.view.GestureDetector.<init>(GestureDetector.java:402)
	at com.amplitude.android.internal.gestures.AutocaptureWindowCallback.<init>(AutocaptureWindowCallback.kt:19)
	at com.amplitude.android.utilities.DefaultEventUtils.startUserInteractionEventTracking(DefaultEventUtils.kt:146)
	at com.amplitude.android.plugins.AndroidLifecyclePlugin.onActivityResumed(AndroidLifecyclePlugin.kt:113)
	at com.amplitude.android.plugins.AndroidLifecyclePlugin$setup$1.invokeSuspend(AndroidLifecyclePlugin.kt:65)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:101)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:832)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)
	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@638111d, Dispatchers.Default]

Possible Solution

Possibly, GestureDetector is initialized too early. The error occurs only in version 1.19.3, indicating that PR 232 changed some behavior.

Steps to Reproduce

@OptIn(ExperimentalAmplitudeFeature::class)
@Singleton
class AmplitudeAnalytics @Inject constructor(@ApplicationContext context: Context) : Analytics {
    private val analytics: Amplitude

    init {
        val trackingOptions = TrackingOptions()
        trackingOptions.disableCity().disableIpAddress().disableLatLng()

        analytics = Amplitude(
            Configuration(
                apiKey = "your-api-key",
                context = context,
                trackingOptions = trackingOptions,
                autocapture = autocaptureOptions {
                    +sessions
                    +appLifecycles
                    +elementInteractions
                }
            )
        )
    }
}

Environment

Any Android device

@bezmian bezmian changed the title Crash when using Autocapture on version 1.19.3 ❗ Crash when using Autocapture on version 1.19.3 Jan 22, 2025
@igor-amp
Copy link
Contributor

@bezmian Thank you for posting this. There is a bug in our test cases and we missed +elementInteractions check. We are moving plugin handling back to main thread. Fix will be ready in next release, today.

@igor-amp
Copy link
Contributor

Resolved in new release 1.19.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants