Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android App Crashes #187

Open
suryapermana92work opened this issue Jan 17, 2024 · 8 comments
Open

Android App Crashes #187

suryapermana92work opened this issue Jan 17, 2024 · 8 comments

Comments

@suryapermana92work
Copy link

suryapermana92work commented Jan 17, 2024

I am getting app crashes while in App.js, instantiating a Rollbar Client

Steps to reproduce
"react": "18.2.0",
"react-native": "0.71.4",
"rollbar": "^2.26.2",
"rollbar-react-native": "^1.0.0-beta.2"

Platforms
Android

JavaScript runtime
Hermes

Workflow
React Native (without Expo)

Build type
Release mode

Device
Real device

import { Client } from 'rollbar-react-native'

const rollbar = new Client({
  accessToken: "POST_CLIENT_ITEM_ACCESS_TOKEN",
  captureUncaught: true,
  captureUnhandledRejections: true
})
@waltjones
Copy link
Contributor

@suryapermana92work thank you for the report. Can you include details of the crash?

@suryapermana92work
Copy link
Author

Screenshot_1705505587

@suryapermana92work
Copy link
Author

@suryapermana92work thank you for the report. Can you include details of the crash?

@waltjones pls let me know if you need any more info

@gsonego
Copy link

gsonego commented Feb 10, 2024

Hi, I'm also facing similar issue..
I've used the rollbar react-native SDK but also the react SDK and both are failing.
The app crashes when trying to send any info to Rollbar.

It works fine on Expo Go, Android Simulator and also web version, but crashes on Android real device.

image

@jfbaraky
Copy link

jfbaraky commented Oct 8, 2024

Having the same issue here after updated to 1.0.0-beta.4
0.9.3 was working normally, but it's not working with the new iOS version :/

@aaronabf
Copy link

aaronabf commented Dec 9, 2024

Any updates on this?

@waltjones
Copy link
Contributor

Hi all,

I have tested here with a hardware Pixel device, and do not get this error. The error looks like the Rollbar Android SDK was not initialized. This is necessary for any project that loads the Java/Android code for rollbar-react-native. It should not be necessary for JS-only projects such as un-ejected Expo projects.

The doc for this is here:
https://docs.rollbar.com/docs/react-native#android

The specific execution that leads to the error is here:
https://github.com/rollbar/rollbar-react-native/blob/master/src/Client.js#L15-L17

That init will be called if React Native's NativeModules returns anything for RollbarReactNative.

If this error is occurring and the init in onCreate is present, it must be executing after the Javascript init. If that matches what anyone is seeing, let me know.

@Jianlong-Nie
Copy link

Jianlong-Nie commented Dec 18, 2024

@waltjones I have added a plugin for Expo, and it is now working properly.

const { withMainApplication, withPlugins } = require("@expo/config-plugins")

function modifyMainApplication(config, options) {
  if (!options || !options.postClientItemAccessToken) {
    throw new Error("Plugin options are missing or undefined.")
  }
  return withMainApplication(config, (config) => {
    const { postClientItemAccessToken, environment } = options
    let mainApplication = config.modResults.contents
    if (!mainApplication.includes("import com.rollbar.RollbarReactNative")) {
      mainApplication = mainApplication.replace(
        "import expo.modules.ReactNativeHostWrapper",
        `import expo.modules.ReactNativeHostWrapper\nimport com.rollbar.RollbarReactNative`
      )
    }
    if (!mainApplication.includes("RollbarReactNative.init")) {
      mainApplication = mainApplication.replace(
        "super.onCreate()",
        `super.onCreate()\n        RollbarReactNative.init(this, "${postClientItemAccessToken}", "${environment}")`
      )
    }
    config.modResults.contents = mainApplication
    return config
  })
}

module.exports = (config, options = {}) =>
  withPlugins(config, [[modifyMainApplication, options]])

then in app.config.js

 plugins: [
    [
      "./plugins/withRollbar.js",
      {
        postClientItemAccessToken,
        environment: isProd ? "production" : "stage"
      }
    ]
]
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants