expo: [Android] [expo-analytics-segment] ExponentSegment: Method addObserver must be called on the main thread

Summary

Hello,

When I try to initialize Segment, I receive this error :

[Unhandled promise rejection: Error: Encountered an exception while calling native method: Exception occurred while executing exported method initialize on module ExponentSegment: Method addObserver must be called on the main thread]

This has been tested with Expo Go on Android device.

Cheers 😄

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

41.0.1

Environment

Expo CLI 4.5.2 environment info: System: OS: macOS 11.2.3 Shell: 5.8 - /bin/zsh Binaries: Node: 14.16.1 - /var/folders/k6/cqlnsz8x0756r83kbyb0s2700000gp/T/fnm-shell-5389680/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.12 - /var/folders/k6/cqlnsz8x0756r83kbyb0s2700000gp/T/fnm-shell-5389680/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /Users/colisweb/.rvm/gems/jruby-9.2.13.0/bin/pod SDKs: iOS SDK: Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 IDEs: Android Studio: 3.5 AI-191.8026.42.35.5791312 Xcode: 12.4/12D4e - /usr/bin/xcodebuild npmPackages: expo: ~41.0.1 => 41.0.1 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz => 0.63.2 react-native-web: ~0.13.12 => 0.13.18 npmGlobalPackages: expo-cli: 4.5.2 Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

Here is a minimalistic repo

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 12
  • Comments: 33 (10 by maintainers)

Most upvoted comments

Hi! Any chances to get this working on Expo 41? I believe that it has been fixed here https://github.com/expo/expo/pull/13263

Any updates on this? Observing the same issue on android, no Segment events are being registered as a result

The beta was just updated so you should be able to install the new Expo Go client (expo client:install:android) - I just tested and verified its working now

In the future we’ll be documenting updates to the beta during testing, so you’ll have better visibility on when changes are available for use!

Failed call payload:

{
  "anonymousId": "308c9dfe-5369-4042-96e9-6d65c63793c9",
  "channel": "server",
  "context": {
    "app": {
      "build": "152",
      "name": "Expo Go",
      "namespace": "host.exp.exponent",
      "version": "2.21.2"
    },
    "device": {
      "id": "dbf50a9d2b617b20",
      "manufacturer": "samsung",
      "model": "SM-N960U",
      "name": "crownqltesq",
      "type": "android"
    },
    "ip": "173.195.183.120",
    "library": {
      "name": "analytics-android",
      "version": "4.9.4"
    },
    "locale": "en-US",
    "network": {
      "bluetooth": false,
      "carrier": "Verizon",
      "cellular": false,
      "wifi": true
    },
    "os": {
      "name": "Android",
      "version": "10"
    },
    "screen": {
      "density": 2.625,
      "height": 2094,
      "width": 1080
    },
    "timezone": "America/Los_Angeles",
    "traits": {
      "anonymousId": "308c9dfe-5369-4042-96e9-6d65c63793c9"
    },
    "userAgent": "Dalvik/2.1.0 (Linux; U; Android 10; SM-N960U Build/QP1A.190711.020)"
  },
  "event": "tree - registration",
  "integrations": {},
  "messageId": "e6536ff0-f8d7-42fe-a1a2-fc90a874fb69",
  "originalTimestamp": "2021-06-30T17:19:34.218Z",
  "projectId": "c9wWbBaJpbaQdLg2UBmjg6",
  "properties": {
    "# trees created": 1,
    "type": "tree",
    "userId": "dc4ee655-2679-48ef-628d-d8442cd7df10"
  },
  "receivedAt": "2021-06-30T17:20:04.937Z",
  "sentAt": "2021-06-30T17:20:04.484Z",
  "timestamp": "2021-06-30T17:19:34.671Z",
  "type": "track",
  "version": 2,
  "writeKey": "Hactts0xLZfE9kBmUUlOLuYX00000000"
}

@snowshiva I was having the same issue a couple of days ago and I fixed my bug today. I was somehow calling Segment.identify() before Segment.initialize(). I fixed my flow and now every Segment.track() call contains the userId as expected. I hope this helps.

@ajsmth I spoke too soon - while data is flowing into segment now, all calls from android are failing because my destination in segment requires userId for trackWithProperties, and for some reason that is automatically being passed for my iOS source but not my Android source. I’m testing now if I can manually include userId to fix in the short run but seems like something is still wrong there.

@ajsmth is the next beta release going to be mentioned on the Expo blog?

iOS events working fine in Segment, android doesn’t work at all. expo diagnostics

    System:
      OS: macOS 11.2.1
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 14.2.0 - ~/.asdf/installs/nodejs/14.2.0/bin/node
      Yarn: 1.22.10 - ~/.asdf/installs/nodejs/14.2.0/.npm/bin/yarn
      npm: 6.14.4 - ~/.asdf/installs/nodejs/14.2.0/bin/npm
    SDKs:
      iOS SDK:
        Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
      Android SDK:
        API Levels: 30
        Build Tools: 30.0.3
        System Images: android-30 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 4.1 AI-201.8743.12.41.7042882
      Xcode: 12.4/12D4e - /usr/bin/xcodebuild
    npmPackages:
      expo: ^42.0.0-beta.1 => 42.0.0-beta.1 
      react: 16.13.1 => 16.13.1 
      react-dom: 16.13.1 => 16.13.1 
      react-native: https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz => 0.63.2 
      react-native-web: ~0.13.12 => 0.13.18 
    npmGlobalPackages:
      expo-cli: 4.7.1
    Expo Workflow: managed

This should be available in Expo 42 - the beta is out now! https://blog.expo.io/expo-sdk-42-beta-is-now-available-e505770389e7