expo: ExpoFirebaseAnalytics throws exceptions on Android

๐Ÿ› Bug Report

Summary of Issue

I am not sure the cause, but this error is happening fairly frequently since I released

Using the standard react-navigation template

function Nav({startupNotification, deregisterNotificationListener}) {
    const ref = React.useRef();
    const routeNameRef = React.useRef();

    const { getInitialState } = useLinkingPatch(ref, {
        prefixes: deepLinkPrefixes,
        config
    });
    const [isReady, setIsReady] = React.useState(false);
    const [initialState, setInitialState] = React.useState();


    React.useEffect(() => {
        Promise.race([
          getInitialState(),
            new Promise(resolve =>
                // Timeout in 150ms if `getInitialState` doesn't resolve
                // Workaround for https://github.com/facebook/react-native/issues/25675
                setTimeout(resolve, 250)
            ),
        ])
            .catch(e => {
                console.error(e);
            })
            .then(state => {
              console.log('InitialUrl returned', state)
              if (!state || !state.routes) {
                console.log('State was undefined')

              } else {
                  setInitialState(state);
              }

                setIsReady(true);
            });
    }, [getInitialState]);

    if (!isReady) {
        console.log('No deep link found')
      return null
    }
    console.log(`Initial state: ${JSON.stringify(initialState)}`);

    return (
        <NavigationContainer initialState={initialState} ref={ref}
                             onReady={() => routeNameRef.current = ref.current.getCurrentRoute().name}
                             onStateChange={() => {
                               const previousRouteName = routeNameRef.current;
                               const currentRouteName = ref.current.getCurrentRoute().name

                               if (previousRouteName !== currentRouteName) {
                                 // The line below uses the expo-firebase-analytics tracker
                                 // https://docs.expo.io/versions/latest/sdk/firebase-analytics/
                                 // Change this line to use another Mobile analytics SDK
                                 Analytics.setCurrentScreen(currentRouteName).then(r =>
                                   console.log('Current screen', currentRouteName, r)
                                 ).catch(e => {
                                   reportError("Could not send analytics",e)
                                 });
                               }

                               // Save the current route name for later comparision
                               routeNameRef.current = currentRouteName;
                             }}
        >
          <StoreProvider>
            <NotificationProvider>
              <AuthStack startupNotification={startupNotification}
                         deregisterNotificationListener={deregisterNotificationListener}/>
            </NotificationProvider>
          </StoreProvider>
        </NavigationContainer>
    )
}                      

From Sentry

Stack 1:

Error: Encountered an exception while calling native method: Exception occurred while executing exported method setCurrentScreen on module ExpoFirebaseAnalytics: Attempt to invoke virtual method 'void android.app.Activity.runOnUiThread(java.lang.Runnable)' ...
  at anonymous(index.android.bundle:1:127775)
  at anonymous(index.android.bundle:1:589676)
  at call(native)
  at apply(native)
  at v(index.android.bundle:1:2602416)
  at anonymous(index.android.bundle:1:2603231)
  at call(native)
  at y(index.android.bundle:1:245199)
  at anonymous(index.android.bundle:1:246198)
  at anonymous(index.android.bundle:1:245337)
  at call(native)
  at y(index.android.bundle:1:245199)
  at o(index.android.bundle:1:245422)
  at anonymous(index.android.bundle:1:245866)
  at c(index.android.bundle:1:266168)
  at b(index.android.bundle:1:267485)
  at _(index.android.bundle:1:266264)
  at h(index.android.bundle:1:245828)
  at anonymous(index.android.bundle:1:245775)
  at anonymous(index.android.bundle:1:245337)
  at anonymous(index.android.bundle:1:247593)
  at setCurrentScreen(index.android.bundle:1:2603150)
  at anonymous(index.android.bundle:1:2600275)
  at call(native)
  at y(index.android.bundle:1:245199)
  at anonymous(index.android.bundle:1:246198)
  at anonymous(index.android.bundle:1:245337)
  at call(native)
  at y(index.android.bundle:1:245199)
  at o(index.android.bundle:1:245422)
  at anonymous(index.android.bundle:1:245866)
  at c(index.android.bundle:1:266168)
  at b(index.android.bundle:1:267485)
  at _(index.android.bundle:1:266264)
  at h(index.android.bundle:1:245828)
  at anonymous(index.android.bundle:1:245775)
  at anonymous(index.android.bundle:1:245337)
  at anonymous(index.android.bundle:1:247593)
  at anonymous(index.android.bundle:1:2600138)
  at onStateChange(index.android.bundle:1:1729770)
  at anonymous(index.android.bundle:1:1747852)
  at Ri(index.android.bundle:1:202073)
  at Xa(index.android.bundle:1:217306)
  at anonymous(index.android.bundle:1:311820)
  at un(index.android.bundle:1:183133)
  at Ya(index.android.bundle:1:217133)
  at Ia(index.android.bundle:1:209434)
  at anonymous(index.android.bundle:1:183542)
  at anonymous(index.android.bundle:1:311820)
  at un(index.android.bundle:1:183133)

Stack 2:

Error: Attempt to invoke virtual method 'android.content.Context android.content.ContextWrapper.getApplicationContext()' on a null object reference
  at anonymous(index.android.bundle:1:127775)
  at anonymous(index.android.bundle:1:589676)
  at call(native)
  at apply(native)
  at v(index.android.bundle:1:2602416)
  at anonymous(index.android.bundle:1:2603661)
  at call(native)
  at y(index.android.bundle:1:245199)
  at anonymous(index.android.bundle:1:246198)
  at anonymous(index.android.bundle:1:245337)
  at call(native)
  at y(index.android.bundle:1:245199)
  at o(index.android.bundle:1:245422)
  at anonymous(index.android.bundle:1:245866)
  at c(index.android.bundle:1:266168)
  at b(index.android.bundle:1:267485)
  at _(index.android.bundle:1:266264)
  at h(index.android.bundle:1:245828)
  at anonymous(index.android.bundle:1:245775)
  at anonymous(index.android.bundle:1:245337)
  at anonymous(index.android.bundle:1:247593)
  at setUserProperties(index.android.bundle:1:2603584)
  at anonymous(index.android.bundle:1:2599466)
  at call(native)
  at y(index.android.bundle:1:245199)
  at anonymous(index.android.bundle:1:246198)
  at anonymous(index.android.bundle:1:245337)
  at call(native)
  at y(index.android.bundle:1:245199)
  at o(index.android.bundle:1:245422)
  at anonymous(index.android.bundle:1:245866)
  at c(index.android.bundle:1:266168)
  at b(index.android.bundle:1:267485)
  at _(index.android.bundle:1:266264)
  at h(index.android.bundle:1:245828)
  at anonymous(index.android.bundle:1:245775)
  at anonymous(index.android.bundle:1:245337)
  at anonymous(index.android.bundle:1:247593)
  at c(index.android.bundle:1:2599333)
  at N(index.android.bundle:1:1995451)
  at anonymous(index.android.bundle:1:1995946)
  at f(index.android.bundle:1:266135)
  at anonymous(index.android.bundle:1:266897)
  at apply(native)
  at anonymous(index.android.bundle:1:270572)
  at x(index.android.bundle:1:269521)
  at y(index.android.bundle:1:269723)
  at callImmediates(index.android.bundle:1:271638)
  at value(index.android.bundle:1:131952)
  at anonymous(index.android.bundle:1:131078)

Environment - output of expo diagnostics & the platform(s) youโ€™re targeting

  Expo CLI 3.24.0 environment info:
    System:
      OS: Windows 10 10.0.18362
    Binaries:
      Node: 10.14.1 - E:\nodejs\node.EXE
      npm: 6.14.4 - E:\nodejs\npm.CMD
    npmPackages:
      expo: ^38.0.0 => 38.0.9
      react: 16.11.0 => 16.11.0
      react-dom: 16.11.0 => 16.11.0
      react-native: 0.62.2 => 0.62.2
      react-native-web: ~0.11.7 => 0.11.7

package.json

"dependencies": {
    "@react-native-community/async-storage": "~1.11.0",
    "@react-native-community/cli": "^4.8.0",
    "@react-native-community/clipboard": "^1.2.3",
    "@react-native-community/masked-view": "0.1.10",
    "@react-navigation/drawer": "^5.8.4",
    "@react-navigation/native": "^5.6.1",
    "@react-navigation/stack": "^5.6.2",
    "build-url": "^2.0.0",
    "cross-fetch": "^3.0.4",
    "dayjs": "^1.8.28",
    "download-file": "^0.1.5",
    "expo": "^38.0.0",
    "expo-apple-authentication": "~2.2.1",
    "expo-asset": "~8.1.7",
    "expo-auth-session": "~1.4.0",
    "expo-constants": "~9.1.1",
    "expo-font": "~8.2.1",
    "expo-linking": "~1.0.3",
    "expo-localization": "~8.2.1",
    "expo-notifications": "~0.7.1",
    "expo-permissions": "~9.1.0",
    "expo-splash-screen": "^0.5.0",
    "expo-updates": "~0.2.8",
    "expo-web-browser": "~8.3.1",
    "i18next": "^17.0.6",
    "metro": "^0.58.0",
    "native-base": "2.13.12",
    "native-base-autocomplete": "^1.3.2",
    "opentype.js": "^1.3.3",
    "papaparse": "^5.2.0",
    "prop-types": "latest",
    "react": "16.11.0",
    "react-dom": "16.11.0",
    "react-i18next": "^10.11.4",
    "react-native": "0.62.2",
    "react-native-action-button": "^2.8.5",
    "react-native-autocomplete-input": "^4.1.0",
    "react-native-device-info": "^5.6.2",
    "react-native-dialog": "^5.6.0",
    "react-native-email": "^1.0.2",
    "react-native-error-boundary": "^1.1.0",
    "react-native-flags-kit": "^1.0.1",
    "react-native-gesture-handler": "~1.6.0",
    "react-native-hyperlink": "0.0.19",
    "react-native-iap": "^4.4.3",
    "react-native-modal": "^11.5.6",
    "react-native-picker-select": "^6.6.0",
    "react-native-popover-view": "^2.0.7",
    "react-native-popup-menu": "^0.15.7",
    "react-native-prompt-android": "^1.1.0",
    "react-native-reanimated": "~1.9.0",
    "react-native-safe-area-context": "~3.0.7",
    "react-native-screens": "~2.9.0",
    "react-native-snap-carousel": "^3.9.0",
    "react-native-svg": "12.1.0",
    "react-native-swipe-list-view": "^3.1.3",
    "react-native-unimodules": "~0.10.1",
    "react-native-web": "~0.11.7",
    "react-redux": "^5.0.7",
    "react-router-native": "^4.3.0",
    "recompose": "^0.30.0",
    "redux": "^4.0.5",
    "redux-debounced": "^0.5.0",
    "redux-persist": "^6.0.0",
    "redux-thunk": "^2.3.0",
    "sentry-expo": "2.1.2",
    "underscore": "^1.10.2",
    "expo-firebase-analytics": "~2.4.1"
  }

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Ah I see. This issue will be fixed in Expo client for SDK 40. In you are using bare, you can use it already by using the version from npm.

@celandro I expect to have a new release of expo-firebase-analytics out tomorrow.

@bitttttten Yes the activity checking is now also performed when logging events. So what was happening, was that in certain situations the current-activity could not be obtained. This could lead to an exception when accessed. This is now handled correctly and it will cause the return promise to be rejected.

Hi! Thanks for reporting this. Weโ€™ve just merged a fix for this problem, however it hasnโ€™t been released it yet. If you are using bare we could release a version for you. Would that be helpful?