aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.44k stars 2.13k forks source link

crash with react native push #13988

Closed stefoid closed 1 week ago

stefoid commented 2 weeks ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Push Notifications

Amplify Version

v6

Amplify Categories

notifications

Backend

None

Environment information

``` # Put output below this line System: OS: macOS 14.2.1 CPU: (6) x64 Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz Memory: 165.29 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 20.0.0 - ~/.nvm/versions/node/v20.0.0/bin/node Yarn: 1.22.11 - /usr/local/bin/yarn npm: 9.6.4 - ~/.nvm/versions/node/v20.0.0/bin/npm Watchman: 2024.07.15.00 - /usr/local/bin/watchman Browsers: Chrome: 130.0.6723.92 Safari: 17.2.1 npmPackages: @aws-amplify/react-native: ^1.1.6 => 1.1.5 @aws-amplify/rtn-push-notification: ^1.2.31 => 1.2.31 @babel/core: ^7.20.12 => 7.25.2 @babel/runtime: ^7.20.13 => 7.25.4 @bam.tech/react-native-image-resizer: ^3.0.5 => 3.0.10 @intercom/intercom-react-native: ^6.8.1 => 6.8.1 @openspacelabs/react-native-zoomable-view: ^2.1.6 => 2.1.6 @react-native-async-storage/async-storage: ^1.24.0 => 1.24.0 @react-native-clipboard/clipboard: 1.13.2 => 1.13.2 @react-native-community/cli: ^13.6.9 => 13.6.9 @react-native-community/cli-platform-android: ^13.6.9 => 13.6.9 @react-native-community/datetimepicker: ^3.4.3 => 3.5.2 @react-native-community/masked-view: ^0.1.11 => 0.1.11 @react-native-community/netinfo: ^11.3.2 => 11.3.2 @react-native-community/slider: ^3.0.3 => 3.0.3 @react-native-firebase/analytics: ^18.9.0 => 18.9.0 @react-native-firebase/app: ^18.9.0 => 18.9.0 @react-native-firebase/crashlytics: ^18.9.0 => 18.9.0 @react-native-firebase/perf: ^18.9.0 => 18.9.0 @react-native-google-signin/google-signin: ^7.2.2 => 7.2.2 @react-native-picker/picker: ^2.7.7 => 2.7.7 @react-native/babel-preset: 0.74.87 => 0.74.87 @react-native/eslint-config: 0.74.87 => 0.74.87 @react-native/metro-config: 0.74.87 => 0.74.87 @react-native/typescript-config: 0.74.87 => 0.74.87 @react-navigation/material-bottom-tabs: ^6.2.12 => 6.2.29 @react-navigation/material-top-tabs: ^6.6.0 => 6.6.14 @react-navigation/native: ^6.0.8 => 6.1.18 @react-navigation/stack: ^6.2.0 => 6.4.1 @sayem314/react-native-keep-awake: ^1.1.0 => 1.2.4 @segment/analytics-react-native: ^2.12.0 => 2.19.4 @segment/sovran-react-native: ^0.4.4 => 0.4.5 @shopify/flash-list: ^1.5.0 => 1.7.1 @tsconfig/react-native: ^2.0.2 => 2.0.3 @types/jest: ^29.2.1 => 29.5.12 @types/react: ^18.2.6 => 18.3.4 @types/react-test-renderer: ^18.0.0 => 18.3.0 HelloWorld: 0.0.1 SignatureCaptureExample: 0.0.1 aws-amplify: ^6.8.0 => 6.6.0 aws-amplify/adapter-core: undefined () aws-amplify/analytics: undefined () aws-amplify/analytics/kinesis: undefined () aws-amplify/analytics/kinesis-firehose: undefined () aws-amplify/analytics/personalize: undefined () aws-amplify/analytics/pinpoint: undefined () aws-amplify/api: undefined () aws-amplify/api/server: undefined () aws-amplify/auth: undefined () aws-amplify/auth/cognito: undefined () aws-amplify/auth/cognito/server: undefined () aws-amplify/auth/enable-oauth-listener: undefined () aws-amplify/auth/server: undefined () aws-amplify/data: undefined () aws-amplify/data/server: undefined () aws-amplify/datastore: undefined () aws-amplify/in-app-messaging: undefined () aws-amplify/in-app-messaging/pinpoint: undefined () aws-amplify/push-notifications: undefined () aws-amplify/push-notifications/pinpoint: undefined () aws-amplify/storage: undefined () aws-amplify/storage/s3: undefined () aws-amplify/storage/s3/server: undefined () aws-amplify/storage/server: undefined () aws-amplify/utils: undefined () babel-jest: ^29.6.3 => 29.7.0 babel-plugin-transform-remove-console: ^6.9.4 => 6.9.4 bson: 4.4.0 => 4.4.0 (4.7.2) cobrowse-sdk-react-native: ^2.11.2-unredaction.0 => 2.19.0 deprecated-react-native-prop-types: ^4.0.0 => 4.2.3 (2.3.0) eslint: ^8.19.0 => 8.57.0 eslint-plugin-react-hooks: ^4.6.0 => 4.6.2 example: 0.0.1 html-entities: ^2.5.2 => 2.5.2 i18n-js: ^3.8.0 => 3.9.2 jest: ^29.6.3 => 29.7.0 libphonenumber-js: ^1.10.19 => 1.11.7 libphonenumber-js/build: undefined () libphonenumber-js/core: undefined () libphonenumber-js/max: undefined () libphonenumber-js/max/metadata: undefined () libphonenumber-js/min: undefined () libphonenumber-js/min/metadata: undefined () libphonenumber-js/mobile: undefined () libphonenumber-js/mobile/examples: undefined () libphonenumber-js/mobile/metadata: undefined () linkify-html: ^4.1.1 => 4.1.3 linkifyjs: ^4.1.1 => 4.1.3 lodash: ^4.17.15 => 4.17.21 moment: ^2.24.0 => 2.30.1 moment-timezone: ^0.5.40 => 0.5.45 mustache: ^3.0.1 => 3.2.1 patch-package: ^6.5.1 => 6.5.1 prettier: 2.8.8 => 2.8.8 prop-types: ^15.6.0 => 15.8.1 react: 18.2.0 => 18.2.0 react-content-loader: ^6.2.0 => 6.2.1 react-content-loader/native: undefined () react-native: 0.74.5 => 0.74.5 react-native-actions-sheet: ^0.8.21 => 0.8.29 react-native-animated-dots-carousel: ^1.0.2 => 1.0.2 react-native-autolink: ^4.2.0 => 4.2.0 react-native-background-fetch: 4.1.8 => 4.1.8 react-native-btr: ^2.2.0 => 2.2.1 react-native-camera: ^3.0.0 => 3.44.3 react-native-config: ^1.5.1 => 1.5.3 react-native-device-info: ^11.1.0 => 11.1.0 (0.9.9, 10.3.0) react-native-document-picker: ^8.1.3 => 8.2.2 react-native-drop-shadow: ^0.0.6 => 0.0.6 react-native-exif: ^0.5.0 => 0.5.0 react-native-exit-app: ^1.1.0 => 1.1.0 react-native-fast-image: ^8.5.8 => 8.6.3 react-native-file-viewer: ^2.0.0 => 2.1.5 react-native-floating-action: ^1.22.0 => 1.22.0 react-native-fs: ^2.18.0 => 2.20.0 react-native-geocoder-reborn: ^0.9.0 => 0.9.0 react-native-geolocation-service: 5.0.0 => 5.0.0 react-native-gesture-handler: ^2.9.0 => 2.18.1 react-native-get-random-values: ^1.11.0 => 1.11.0 react-native-google-places-autocomplete: ^1.8.0 => 1.9.0 react-native-gradle-plugin: ^0.71.15 => 0.71.19 react-native-hyperlink: 0.0.22 => 0.0.22 react-native-image-crop-picker: ^0.41.2 => 0.41.2 react-native-inappbrowser-reborn: ^3.7.0 => 3.7.0 react-native-iphone-x-helper: ^1.3.1 => 1.3.1 react-native-keyboard-accessory: ^0.1.16 => 0.1.16 react-native-keyboard-aware-scroll-view: ^0.9.5 => 0.9.5 react-native-keyboard-spacer: ^0.4.1 => 0.4.1 react-native-localize: ^3.2.1 => 3.2.1 react-native-map-link: ^3.6.1 => 3.6.1 react-native-maps: 1.7.1 => 1.7.1 react-native-modal: 13.0.1 => 13.0.1 react-native-orientation-locker: ^1.7.0 => 1.7.0 react-native-pager-view: ^6.1.4 => 6.4.1 react-native-paper: ^5.0.1 => 5.12.5 react-native-permissions: ^3.10.0 => 3.10.1 react-native-rate: ^1.2.12 => 1.2.12 react-native-render-html: ^6.3.4 => 6.3.4 react-native-responsive-fontsize: ^0.5.1 => 0.5.1 react-native-safe-area-context: ^4.10.0 => 4.10.9 react-native-screens: 3.34.0 => 3.34.0 react-native-section-list-get-item-layout: ^2.2.3 => 2.2.3 react-native-share: ^10.2.1 => 10.2.1 react-native-share-menu: ^6.0.0 => 6.0.0 react-native-signature-capture: 0.4.12 => 0.4.12 react-native-snap-carousel: 4.0.0-beta.6 => 4.0.0-beta.6 react-native-svg: ^13.7.0 => 13.14.1 react-native-tab-view: ^3.5.0 => 3.5.2 react-native-tracking-transparency: ^0.1.2 => 0.1.2 react-native-vector-icons: ^10.1.0 => 10.1.0 react-native-video: ^5.2.1 => 5.2.1 react-native-virtualized-view: ^1.0.0 => 1.0.0 react-native-vision-camera: ^4.5.1 => 4.5.2 react-native-webview: 13.10.4 => 13.10.4 react-native-xml2js: ^1.0.3 => 1.0.3 react-number-format: ^4.9.3 => 4.9.4 react-redux: 8.0.5 => 8.0.5 react-test-renderer: 18.2.0 => 18.2.0 realm: ^12.13.1 => 12.13.1 redux: 4.2.1 => 4.2.1 redux-thunk: 2.4.2 => 2.4.2 rn-fetch-blob: ^0.10.16 => 0.10.16 sp-react-native-in-app-updates: ^1.3.1 => 1.4.0 typescript: 5.0.4 => 5.0.4 uuid: 9.0.0 => 9.0.0 (9.0.1) npmGlobalPackages: corepack: 0.17.2 npm: 9.6.4 ```

Describe the bug

Ive noticed in crashlytics that a small proportion of our users are experiencing this crash bug always at startup.

All I have to go on are the stack traces below. this appears to only be reporting for android devices, but we have few iOS users so I cant guarentee you 100% that it is Android-only.

Expected behavior

no crash

Reproduction steps

  1. I dont have any way to reproduce this

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line Fatal Exception: java.lang.NullPointerException: at com.amazonaws.amplify.rtnpushnotification.PushNotificationModule.shouldShowRequestPermissionRationale(PushNotificationModule.kt:186) at com.amazonaws.amplify.rtnpushnotification.PushNotificationModule.getPermissionStatus(PushNotificationModule.kt:63) at java.lang.reflect.Method.invoke(Method.java) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:146) at com.facebook.jni.NativeRunnable.run(NativeRunnable.java) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27) at android.os.Looper.loopOnce(Looper.java:230) at android.os.Looper.loop(Looper.java:319) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:233) at java.lang.Thread.run(Thread.java:1012) ```

aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

android devices (probably)

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

e

Additional information and screenshots

No response

cwomack commented 2 weeks ago

Hello, @stefois 👋. Can you confirm if this was an upgraded/migrated app from a previous version (e.g. Amplify v4 or v5)? If so, can you see if taking the following steps helps resolve the issue?

If that doesn't help at all, can you share your frontend code where Push Notifications is being used/set up? Thanks.

stefoid commented 2 weeks ago

Hi - to be clear, this bug affects a small percentage of users, sometimes. Potentially the only consistent aspect is it affects android users. Its not something I can replicate myself in my local environment. Our production builds are always from a clean foundation, so those steps (removing node_modules etc...) are not required.

stefoid commented 2 weeks ago
import { initializePushNotifications, getPermissionStatus, onTokenReceived, onNotificationReceivedInForeground, onNotificationOpened, getLaunchNotification, requestPermissions} from 'aws-amplify/push-notifications';
import { Amplify } from 'aws-amplify';

function configure () {

    Amplify.configure({
        Notifications: {
            Push: {
                AWSPinpoint: {
                    appId: 'com.xxx.xxxxx',
                    region: 'ap-southeast-2'
                }
            }
        }
    });

    initializePushNotifications();

    // // get the registration token
    // This will only be triggered when the token is generated or updated.
    onTokenReceived((token) => {
        saveToken(token)
    });

    onNotificationReceivedInForeground((notification) => {
        handleNotification(notification)
    });

    onNotificationOpened((notification) => {
        handleNotification(notification)
    });
}
cwomack commented 1 week ago

@stefoid, we see Push Notifications working as expected on our side and can't reproduce the issue you're running in to.

There might be a few related issues within the React Native repo (see here) tied to Android crashes happening based on different client environments, versions, etc. If you can find a way to reproduce this consistently or provide can provide a sample repo that does, definitely let us know so we can dig into it further and reopen. For now, we'll close this issue until there's a way to consistently reproduce.

stefoid commented 1 week ago

OK, Ill keep an eye on it.

So there is nothing you can gatehr from inspecting the code in this file?

   at com.amazonaws.amplify.rtnpushnotification.PushNotificationModule.shouldShowRequestPermissionRationale(PushNotificationModule.kt:186)