Android App Crashes
Opened this issue · 8 comments
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
})
@suryapermana92work thank you for the report. Can you include details of the crash?
@suryapermana92work thank you for the report. Can you include details of the crash?
@waltjones pls let me know if you need any more info
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 :/
Any updates on this?
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.
@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"
}
]
]