Skip to content

[Android] Error on setup: "Method addObserver must be called on the main thread" #255

Closed
@cristeahub

Description

@cristeahub

Hi,

After upgrading one of my other dependencies in my android app (namely Stripe Android SDK from 10.x to 16.x) I surprisingly encountered an error in this SDK. Note that one of the changes from this huge jump is that the StripeSDK has migrated to AndroidX.

When i do analytics.setup(MY_WRITE_KEY, {some: 'options'} I get a redbox in my app with the text writeKey must not be null or empty.

I have debugged and verified that the writeKey is indeed set correctly, so this is just a symptom and not the actual issue.

Digging further down I found that when initializing the Segment Android SDK I got the following error Method addObserver must be called on the main thread. This seems to be the actual issue causing my subsequent calls to analytics to fail due to the writeKey not being set.

The error is caught here:

} catch(e2: IllegalStateException) {
// pass if the error is due to calling setSingletonInstance multiple times
// if you created singleton in native code already,
// you need to promise.resolve for RN to properly operate

This error comes from the analytics-android package that this package depends on. The error seems to stem from AndroidX issues, and there's even an issue on that repo for the error: segmentio/analytics-android#725 .

This is a blocker for us now, I am asking here since we are using react native and there was no answer from the developers at the other repo. Is there a way to escalate this issue so it gets attention and gets fixed?

I found a related issue from a different vendor here: getsentry/sentry-android#520 . This issue was about lifetime handlers, which both the original issue creator on the segment-android repo and myself use. However simply turning that off was not enough to fix the issue.

Alternatively do you know of any workarounds?

Thanks for a great library otherwise!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions