Skip to content

Error: Native module not found at getRandomBase64 (Android build error) #1087

@davidwinograd1

Description

@davidwinograd1

Environment:

analytics-react-native version: 2.21.2

React Native version: 0.68.7

Platform: Android

Description:
My React Native app works correctly without Segment Analytics. However, after integrating @segment/analytics-react-native and wrapping my app in , I get the error:

Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.

More specifically, I get [Error: Native module not found] when doing the createClient

Working code (without Segment Analytics):

function AppV2() {
  return (
    <InstantSearch searchClient={searchClient} indexName={POSTS_INDEX_NAME}>
      <Configure clickAnalytics hitsPerPage={50} enablePersonalization={false} />
      <Provider store={store}>
        <StyleProvider style={getTheme(material)}>
          <QueryClientProvider client={queryClient}>
            <Root>
              <AppNavigator />
            </Root>
          </QueryClientProvider>
        </StyleProvider>
      </Provider>
    </InstantSearch>
  );
}

Failing code (with Segment Analytics):

const segmentClient = createClient({
  writeKey: SEGMENT_WRITE_KEY,
  trackAppLifecycleEvents: true,
  useSegmentEndpoints: false,
});
segmentClient.add({ plugin: new InjectTraits() });

function AppV2() {
  return (
    <InstantSearch searchClient={searchClient} indexName={POSTS_INDEX_NAME}>
      <Configure clickAnalytics hitsPerPage={50} enablePersonalization={false} />
      <AnalyticsProvider client={segmentClient}>
        <Provider store={store}>
          <StyleProvider style={getTheme(material)}>
            <QueryClientProvider client={queryClient}>
              <Root>
                <AppNavigator />
              </Root>
            </QueryClientProvider>
          </StyleProvider>
        </Provider>
      </AnalyticsProvider>
    </InstantSearch>
  );
}

Steps to reproduce:

Start with working React Native app as above (without Analytics).
Add @segment/analytics-react-native (v2.21.2) and initialize client as shown.
Wrap the app with using the Segment client.
Build and run on Android.

Expected behavior:
App loads and runs normally with Segment Analytics enabled.

Actual behavior:
App crashes immediately with:
Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions