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
[CRASH][ANDROID] NullPointerException in getDeviceState #1159
Comments
+1.
|
Howdy Diego, Can you please include the code you're using? Also can you please provide environment info (e.g: device make and model, OS, etc...)? Cheers |
Thanks for your reply. It's being reported on our Google Play console at the rate of about 50 crashes per week, I don't have any way to reproduce it. |
Same here. info Fetching system and libraries information... "react-native": "0.63.3", Fatal Exception: java.lang.NullPointerException com.geektime.rnonesignalandroid.RNOneSignal.getDeviceState (RNOneSignal.java:239) |
Please provide a code snippet in order to facilitate reproduction. Cheers |
The error occur in OneSignal.getDeviceState() call: const getDeviceState = async () => {
const deviceState = await OneSignal.getDeviceState();
console.log({ deviceState });
} The exception is: Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'org.json.JSONObject com.onesignal.OSDeviceState.toJSONObject()' on a null object reference
com.geektime.rnonesignalandroid.RNOneSignal.getDeviceState (RNOneSignal.java:239)
java.lang.reflect.Method.invoke (Method.java)
com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:151)
com.facebook.react.bridge.queue.NativeRunnable.run (NativeRunnable.java)
android.os.Handler.handleCallback (Handler.java:883)
android.os.Handler.dispatchMessage (Handler.java:100)
com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27)
android.os.Looper.loop (Looper.java:241)
com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:226)
java.lang.Thread.run (Thread.java:919) The OneSignal and React Native packages are: "react-native": "0.63.3",
"react-native-onesignal": "^4.0.1", The react native info: info Fetching system and libraries information...
System:
OS: macOS 10.15.7
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 36.86 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.22.0 - ~/.nvm/versions/node/v10.22.0/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.6 - ~/.nvm/versions/node/v10.22.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.0 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 13.6, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 23, 25, 26, 28, 29
Build Tools: 28.0.3, 29.0.2, 29.0.3
Android NDK: Not Found
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6308749
Xcode: 11.6/11E708 - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_242 - /usr/bin/javac
Python: 2.7.16 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.13.1 => 16.13.1
react-native: 0.63.3 => 0.63.3
react-native-macos: Not Found
npmGlobalPackages:
react-native: Not Found |
Getting same issue. "react-native": "^0.63.4", I upgraded from "react-native-onesignal": "^3.9.3" to "react-native-onesignal": "^4.0.3". I am getting crashes now. I have updated the init code same as above. I added freshly. ... From Play Store Crash Log java.lang.NullPointerException: Firebase Crash log Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.onesignal.g0.a()' on a null object reference |
Howdy,
doesn't quite provide enough information to reproduce. What we need is some more context as to how and where this is being used. E.g: how does the call to Please make sure to provide all the context necessary to resolve this since the stack traces provided don't quite provide what we need. I suspect this might be happening if Remember that |
Hi, in the App.tsx, our entry point, we have: const oneSignalIntialize = async () => {
OneSignal.setAppId('xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx');
}
const App = () => {
useEffect(() => {
oneSignalIntialize();
}, []);
return (
<LoginFlow />
);
} After the login flow, if this was succeed, we have a welcome screen: const getDeviceState = async () => {
const deviceState = await OneSignal.getDeviceState();
console.log({ deviceState });
}
const WelcomeScreen = () => {
useEffect(() => {
getDeviceState();
}, []);
return (
<Components />
);
} |
Hi @renatobentorocha , |
Hi @tyang1 Thanks by attention, but the one-signal docs for that callback (getPermissionSubscriptionState) say: I will test with |
Getting this also. Don’t know how to reproduce. @rgomezp perhaps it’s a threading issue? This happens randomly, but quite a lot. We see many traces for in our crash report |
Howdy, It is interesting @renatobentorocha that you report it is happening 98% in background. @oferRounds @dijinshopwise is this something you are also seeing? |
+1 |
@rgomezp follow the code: async componentDidMount() {
this._isMounted = true
/* O N E S I G N A L S E T U P */
OneSignal.setAppId('***********************************')
OneSignal.setLogLevel(0, 0)
OneSignal.setRequiresUserPrivacyConsent(false)
/* O N E S I G N A L H A N D L E R S */
OneSignal.setNotificationWillShowInForegroundHandler(notifReceivedEvent => {
let notification = notifReceivedEvent.getNotification()
const buttonOk = {
text: 'OK', onPress: () => {
notifReceivedEvent.complete()
},
}
Alert.alert(notification.title, notification.body, [buttonOk])
if (notification.additionalData) {
//
}
})
OneSignal.setNotificationOpenedHandler(notification => {
//
})
OneSignal.disablePush(true)
const deviceState = await OneSignal.getDeviceState()
if (Platform.OS === 'ios' && !deviceState.isSubscribed) {
OneSignal.promptForPushNotificationsWithUserResponse(function(accepted) {
//
});
}
// ...
} |
I downgrade to old version and Google Play warns about same error.
|
Any suggestion? Any temporary solution? |
@diego-paired our temporary workaround was to delay the call to |
thanks for the tip |
I followed the @rgomezp suggestion and the crashes, for now, stopped occur. OneSignal.addSubscriptionObserver(() => {
OneSignal.getDeviceState().then((deviceState) => {
console.log({deviceState})
});
}); |
Using the test app, added this code to a button: Situation 1
Log shows:
However when using the example code provided in the componentDidMount: Situation 2
The log shows:
@rgomezp is scenario 1 expected behavior? @diego-paired @renatobentorocha @dan-developer could y'all share your examples or confirm if both above situations is what you see? Please be detailed in how you are using this method and include steps for us to reproduce. |
@jfishman1 Take a look at the documentation. You will see that Regardless, it appears there's a good opportunity to handle this in the SDK to avoid these crashes. Thanks for surfacing. We will explore what changes can be made to more seamlessly handle these. |
Digging into this a bit further, it appears that the most likely cause of this is the native side is trying to get the device state before the context has loaded.
To confirm, please look for In the meantime, it seems we can add a check in the Android bridge to prevent a full on crash. Regardless, please note: Thanks for your patience y'all. From #1085: OneSignal.addSubscriptionObserver(async (event) => {
this.OSLog("OneSignal: subscription changed:", event);
if (event.to.isSubscribed) {
const state = await OneSignal.getDeviceState();
// do something with the device state
}
}); |
Update: this is now fixed in the latest version 4.0.7 |
I updated to the latest 4.0.7 repo. I am not sure if I am asking on the right place but on some iOS simulators and Android devices I even only get these fields with deviceState for example like this one. There is even no userId field.
|
I've tried that but it is not 100% work, like sometimes i got the device id sometimes not, mostly the negative case happens when on the first launch of the app. So i have to close the app first, then the device id will be fetch successfully. |
Is there any body still getting this error in 28 July 2022 or only me? |
Getting the same error. However not often or rarely on some of devices like Redmi and Infinix. |
Same issue here, any solution yet? |
Description:
We're receiving a number of crash reports originating in
RNOneSignal.getDeviceState
, stack trace attached below.It affects every android SDK version and manufacturer.
Environment
"react-native-onesignal": "^4.0.2",
react: 17.0.1 => 17.0.1 react-native: 0.64.0-rc.2 => 0.64.0-rc.2
Steps to Reproduce Issue:
Haven't been able to reproduce the issue, it's reported on Google Play's crash dashboard.
Anything else:
The text was updated successfully, but these errors were encountered: