Android App Crashes with Rollbar Null Pointer Exception using EAS Build

Expo SDK: 41
Workflow: managed
Platform: Android ONLY

So my app is crashing on Android with the following native error:

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.rollbar.android.Rollbar.configure(com.rollbar.notifier.config.ConfigProvider)' on a null object reference

This ONLY happens with packages built with eas build, and ONLY on Android, iOS works fine.
And if I install the app built from expo build, then it works fine for both platforms.

Anyone has any insights or experience something similar?

Update: I removed rollbar-react-native references from my code ran another eas build again & it worked, so this definitely has something to do with EAS build & rollbar-react-native package for Android.
This is the code where Rollbar is initialized

const rollbar = () => {
  const { env } = getEnvVars()

  const config = new Configuration('[rollbar-app-key]', {
    captureUncaught: true,
    captureUnhandledRejections: true,
    payload: {
      environment: env,
    },
  })

  return env === 'production' || env === 'staging'
    ? new Client(config)
    : { error: () => {}, setPerson: () => {} }
}

rollbar-react-native requires additional setup in MainApplication.onCreate.
for managed workflow, it should require a config plugin to do so.
for your expo build test, did you test on the same managed workflow project?

Hi @kudochien

Thank you so much for the reply!!!

So yeah, I did test with both expo build & eas build, for the app built with expo build, it works totally fine as expected.
Oh one more thing I just noticed today thatā€™s relevant, on Android, the UI even look different comparing the expo build app vs eas build app (see below)

App built with expo build ā† correct UI

App built with eas build ā† UI is off, notice the extra padding & input text cut off a bit

Is this something that SDK42 couldā€™ve fixed, do you think?

P.S. iOS doesnā€™t have any of the issues mentioned here

could you share how you adding RollbarReactNative.init() in MainApplication? because for managed workflow app, assuming there is no any native code like MainApplication.java.

for the text padding issue, there is a related issue: Some issues with EAS build Ā· Issue #12791 Ā· expo/expo Ā· GitHub which expected to be fixed on SDK 42. please have a try for upgrading and let me know if SDK 42 works for you.

Hi, Iā€™m using Expo managed workflow so I didnā€™t change any native code at all, but this is the package I was using, and I basically just followed their doc here

"rollbar-react-native": "^0.9.2",

and here is how I initialize it in React Native code

import { Client, Configuration } from 'rollbar-react-native'
import getEnvVars from 'config/environments'

const rollbar = () => {
  const { env } = getEnvVars() // @env is the env string

  const config = new Configuration('08e1ff04e9a74788af053ec82fe65c54', {
    captureUncaught: true,
    captureUnhandledRejections: true,
    payload: {
      environment: env,
    },
  })

  const client = new Client(config)

  return env === 'production' || env === 'staging' ? client : null
}

// in <ErrorBoundary> component
const errorLogger = rollbar()
errorLogger.error(error, extraInfo)

P.S.: this code works perfectly fine if built with expo build, for both platforms, and also works fine for iOS app built with eas build

hi there!
after taking some time to setup a rollbar project, i found that is an interesting case.
rollbar-react-native sdk can support if native module does not exist.
for expo build, native modules are not supported and make rollbar-react-native works in pure js environment. on the other hand, eas build supports native modules and breaks rollbar-react-native sdk.

a workaround in the meantime is to exclude rollbar-react-native from autolinking by adding react-native.config.js file like this.

module.exports = {
  dependencies: {
    'rollbar-react-native': {
      platforms: {
        android: null,
        ios: null,
      },
    },
  },
};

however, still suggest to use config plugin for adding RollbarReactNative.init() in MainApplication. that would benefit full functionalities from rollbar sdk.

1 Like

Hi @kudochien

Thank you SO much for providing a solution & explanation! I get it now!!!
That said, because we donā€™t have any Native app developers, we are probably only gonna try the react-native.config.js approach and will report back here for the findings :frowning:

Last but not least, Iā€™m still curious as to why rollbar-react-native built with eas build worked on iOS but not Android tho? Did the linking only worked for iOS or something? :thinking:

@shandusdu might come from the difference between rollbar ios sdk and android sdk.
e.g. ios sdk handle null access better.

Hi @kudochien
Thanks a ton for answering the questions & helping us solve the issue, your solution with react-native.config.js totally worked!!
Altho we are likely gonna go with expo build to build our app for now since it was internally tested like this, weā€™ll most definitely switch over to EAS for the next release to take advantage of the much smaller bundle size!

Thank you again for the tremendous help!

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.