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.43k stars 2.13k forks source link

Android: Could not invoke RNPushNotification.getToken #8407

Closed beqramo closed 3 years ago

beqramo commented 3 years ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Push Notifications

Amplify Categories

notifications

Environment information

``` # Put output below this line System: OS: macOS 11.2.1 CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Memory: 902.80 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 14.17.0 - /usr/local/opt/node@14/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 6.14.13 - /usr/local/opt/node@14/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Browsers: Chrome: 91.0.4472.77 Safari: 14.0.3 npmPackages: @argyleio/argyle-plugin-react-native: ^3.0.3 => 3.0.3 @aws-amplify/pushnotification: ^4.0.3 => 4.0.3 @babel/core: ^7.12.9 => 7.14.3 (7.9.0) @babel/plugin-proposal-decorators: 7.12.1 => 7.12.1 (7.14.2) @babel/plugin-proposal-optional-catch-binding: 7.12.1 => 7.12.1 (7.14.2) @babel/runtime: ^7.12.5 => 7.14.0 @expo/react-native-action-sheet: ^3.9.0 => 3.9.0 @gorhom/bottom-sheet: ^3.6.4 => 3.6.4 @hookform/resolvers: ^2.4.0 => 2.5.1 @react-native-async-storage/async-storage: ^1.15.5 => 1.15.5 @react-native-clipboard/clipboard: ^1.7.0 => 1.7.0 @react-native-community/datetimepicker: ^3.4.7 => 3.5.0 @react-native-community/hooks: ^2.6.0 => 2.6.0 @react-native-community/masked-view: ^0.1.11 => 0.1.11 @react-native-community/netinfo: ^6.0.0 => 6.0.0 @react-native-community/push-notification-ios: ^1.8.0 => 1.8.0 (1.0.3) @react-native-picker/picker: ^1.16.1 => 1.16.1 @react-navigation/bottom-tabs: ^5.11.10 => 5.11.11 @react-navigation/native: 5.9.4 => 5.9.4 @react-navigation/stack: 5.14.5 => 5.14.5 @segment/analytics-react-native: ^1.4.4 => 1.4.6 @segment/analytics-react-native-mixpanel: ^1.4.4 => 1.4.6 @sentry/react-native: ^2.4.2 => 2.4.3 @storybook/addon-storyshots: 6.1.10 => 6.1.10 @storybook/react-native: 5.3.23 => 5.3.23 @storybook/react-native-server: 5.3.23 => 5.3.23 @styled-system/theme-get: ^5.1.2 => 5.1.2 @twotalltotems/react-native-otp-input: ^1.3.11 => 1.3.11 @types/i18n-js: 3.0.3 => 3.0.3 @types/jest: 26.0.19 => 26.0.19 (25.2.3, 26.0.23) @types/ramda: 0.27.32 => 0.27.32 @types/react: 16.14.0 => 16.14.0 (17.0.6, 16.14.6) @types/react-native: 0.63.40 => 0.63.40 (0.64.5) @types/react-native-push-notification: ^7.3.0 => 7.3.0 @types/react-test-renderer: 16.9.4 => 16.9.4 @types/styled-components: 5.1.6 => 5.1.6 (5.1.9) @types/styled-components-react-native: ^5.1.1 => 5.1.1 @types/styled-system: ^5.1.11 => 5.1.11 @types/styled-system__should-forward-prop: ^5.1.2 => 5.1.2 @typescript-eslint/eslint-plugin: 4.10.0 => 4.10.0 @typescript-eslint/parser: 4.10.0 => 4.10.0 @unimodules/core: 6.0.0 => 6.0.0 HelloWorld: 0.0.1 add: ^2.0.6 => 2.0.6 amazon-cognito-identity-js: ^5.0.2 => 5.0.2 apisauce: 2.0.0 => 2.0.0 (0.14.3) aws-amplify: ^4.0.3 => 4.0.3 aws-amplify-react-native: ^5.0.1 => 5.0.1 babel-jest: 26.6.3 => 26.6.3 (25.5.1) babel-loader: 8.2.2 => 8.2.2 babel-plugin-module-resolver: ^4.1.0 => 4.1.0 babel-plugin-styled-components: ^1.12.0 => 1.12.0 bufferutil: 4.0.2 => 4.0.2 canvas: 2.6.1 => 2.6.1 class-validator: 1.0.0 computed-types: 1.0.0 dayjs: ^1.10.4 => 1.10.4 detox: 17.14.5 => 17.14.5 eslint: 7.15.0 => 7.15.0 eslint-config-prettier: 7.0.0 => 7.0.0 eslint-config-standard: 16.0.2 => 16.0.2 eslint-plugin-import: 2.22.1 => 2.22.1 eslint-plugin-node: 11.1.0 => 11.1.0 eslint-plugin-promise: 4.2.1 => 4.2.1 eslint-plugin-react: 7.21.5 => 7.21.5 eslint-plugin-react-hooks: ^4.2.0 => 4.2.0 eslint-plugin-react-native: 3.10.0 => 3.10.0 expo-localization: 9.1.0 => 9.1.0 fbjs-scripts: 3.0.0 => 3.0.0 google-libphonenumber: ^3.2.21 => 3.2.21 hermes-inspector-msggen: 1.0.0 i18n-js: 3.8.0 => 3.8.0 io-ts: 1.0.0 jest: ^26.6.3 => 26.6.3 (25.5.4) jest-circus: 25.5.4 => 25.5.4 jest-expo: 40.0.1 => 40.0.1 jetifier: 1.6.6 => 1.6.6 (1.6.8) joi: 1.0.0 libphonenumber-js: ^1.9.17 => 1.9.17 libphonenumber-js-core: 1.0.0 libphonenumber-js-max: 1.0.0 libphonenumber-js-min: 1.0.0 libphonenumber-js-mobile: 1.0.0 memo-parser: 0.2.1 mobx: 6.2.0 => 6.2.0 mobx-react-lite: 3.2.0 => 3.2.0 mobx-state-tree: 5.0.1 => 5.0.1 mocha: 8.2.1 => 8.2.1 moti: ^0.10.1 => 0.10.1 nope: 1.0.0 npm-run-all: 4.1.5 => 4.1.5 patch-package: 6.2.2 => 6.2.2 postinstall-prepare: 1.0.1 => 1.0.1 prettier: 2.2.1 => 2.2.1 ramda: 0.27.1 => 0.27.1 (0.25.0, 0.21.0, 0.24.1) react: 17.0.1 => 17.0.1 (16.14.0) react-devtools-core: 4.10.1 => 4.10.1 (4.13.2) react-dom: 16.14.0 => 16.14.0 react-hook-form: ^7.2.3 => 7.6.2 react-native: 0.64.1 => 0.64.1 react-native-bootsplash: ^3.2.3 => 3.2.3 react-native-clean-project: ^3.6.3 => 3.6.4 react-native-collapsible: ^1.6.0 => 1.6.0 react-native-config: ^1.4.2 => 1.4.2 react-native-dropdownalert: ^4.3.0 => 4.3.0 react-native-fast-image: ^8.3.4 => 8.3.4 react-native-geolocation-service: ^5.3.0-beta.1 => 5.3.0-beta.1 react-native-gesture-handler: ^1.10.3 => 1.10.3 react-native-google-places-autocomplete: ^2.2.0 => 2.2.0 react-native-hyperlink: ^0.0.19 => 0.0.19 react-native-intercom: ^20.1.0 => 20.1.0 react-native-iphone-x-helper: ^1.3.1 => 1.3.1 react-native-keyboard-spacer: ^0.4.1 => 0.4.1 react-native-keychain: 6.2.0 => 6.2.0 react-native-maps: 0.28.0 => 0.28.0 react-native-modal-datetime-picker: ^9.2.3 => 9.2.3 react-native-pager-view: ^5.1.8 => 5.1.9 react-native-permissions: ^3.0.3 => 3.0.3 react-native-picker-select: ^8.0.4 => 8.0.4 react-native-plaid-link-sdk: ^7.0.5 => 7.0.5 react-native-push-notification: ^7.3.1 => 7.3.1 react-native-reanimated: ^2.1.0 => 2.1.0 react-native-safe-area-context: ^3.2.0 => 3.2.0 react-native-screens: ^3.2.0 => 3.2.0 react-native-share: ^6.0.1 => 6.0.1 react-native-splash-screen: 3.2.0 => 3.2.0 react-native-tab-view: ^3.0.1 => 3.0.1 react-native-unimodules: 0.12.0 => 0.12.0 react-native-version: ^4.0.0 => 4.0.0 react-native-web: 0.15.1 => 0.15.1 react-powerplug: 1.0.0 => 1.0.0 react-test-renderer: 17.0.1 => 17.0.1 (17.0.2, 16.11.0) reactotron-mst: 3.1.3 => 3.1.3 reactotron-react-native: 5.0.0 => 5.0.0 rimraf: 3.0.2 => 3.0.2 (2.7.1, 2.6.3, 2.4.5, 2.2.8) solidarity: 2.3.1 => 2.3.1 styled-components: ^5.3.0 => 5.3.0 styled-components/macro: undefined () styled-components/native: undefined () styled-components/primitives: undefined () styled-system: ^5.1.5 => 5.1.5 superstruct: 1.0.0 swr: ^0.5.6 => 0.5.6 toggle-switch-react-native: ^3.2.0 => 3.2.0 typescript: 4.2.3 => 4.2.3 utf-8-validate: 5.0.3 => 5.0.3 validate.js: 0.13.1 => 0.13.1 vest: 1.0.0 yup: ^0.32.9 => 0.32.9 (1.0.0) yup-phone: ^1.2.19 => 1.2.19 zod: 1.0.0 npmGlobalPackages: @aws-amplify/cli: 4.52.0 @mapbox/node-pre-gyp: 1.0.5 expo-cli: 4.0.2 generator-office: 1.7.6 node-gyp: 8.0.0 npm: 6.14.13 react-native-rename: 2.8.0 sql-cli: 0.6.2 yarn: 1.22.10 yo: 3.1.1 ```

Describe the bug

Hi, I can't run an application on android, it throws this error. I found something similar like this https://github.com/aws-amplify/amplify-js/issues/2643#issuecomment-523610933 but it wasn't a solution.

on IOS it works as expected.

Expected behavior

it should not crash on get token

Reproduction steps

configure project and just run it on android

Code Snippet

// Put your code below this line.
import Amplify, { Analytics } from 'aws-amplify';
import { NativeModules, Platform } from 'react-native';
import PushNotification from '@aws-amplify/pushnotification';
import PushNotificationIOS from '@react-native-community/push-notification-ios';

import awsconfig from 'src/aws-exports';

Amplify.configure(awsconfig);

// get the registration token
// This will only be triggered when the token is generated or updated.
PushNotification.onRegister((token) => {
  console.log('in app registration', token);
});

NativeModules.RNPushNotification.getToken((token) => {
  console.log(`PushToken: ${token}`);
});

// request iOS push notification permissions
Platform.OS === 'ios' && PushNotification.requestIOSPermissions();

// get the notification data when notification is received
PushNotification.onNotification((notification) => {
  // Note that the notification object structure is different from Android and IOS
  console.log('in app notification', notification);

  if (Platform.OS === 'ios') {
    notification.finish(PushNotificationIOS.FetchResult.NoData);
  }
});

// get the notification data when notification is opened
PushNotification.onNotificationOpened((notification) => {
  console.log('the notification is opened', notification);
});

Log output

``` // Put your logs below this line ```

aws-exports.js

/* eslint-disable */
// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "us-east-2",
    "aws_cognito_identity_pool_id": "us-east-2:255a7cf2-0147-4e6d-a3aa-955c7b2f2fb3",
    "aws_cognito_region": "us-east-2",
    "oauth": {},
    "aws_mobile_analytics_app_id": "37cd23ae8c7b4a6fa88e9049fe9f48ee",
    "aws_mobile_analytics_app_region": "us-east-1"
};

export default awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

Pixel 3

Mobile Operating System

android 11

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

image

viprocket1 commented 3 years ago

I had a similar issue. You can fix this issue by adding the firebase-iid dependency:

implementation("com.google.firebase:firebase-iid")

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.