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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 android alarm manager error with react native >= 0.68 #445

Closed
alwex opened this issue Jul 2, 2022 · 8 comments 路 Fixed by #449
Closed

馃悰 android alarm manager error with react native >= 0.68 #445

alwex opened this issue Jul 2, 2022 · 8 comments 路 Fixed by #449

Comments

@alwex
Copy link

alwex commented Jul 2, 2022

Hello,

Notification scheduled using the alarm manager does not work anymore since react native version 0.68, was working fine on 0.66

Notification works fine when not using the alarm manager.

When triggering a notification with alarm manager I get this error:

[Error: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference]

Version tested:
0.68.2
0.69.1

reproduction in a bare new react native project, created with npx react-native init notifications --template react-native-template-typescript:

import notifee, {
  AndroidBadgeIconType,
  TimestampTrigger,
  TriggerType,
} from '@notifee/react-native';
import React from 'react';
import {SafeAreaView, Text, TouchableOpacity} from 'react-native';

export const testNotification = async () => {
  try {
    await notifee.requestPermission();
    const channelId = await notifee.createChannel({
      id: 'notification-channel',
      name: 'Reminder',
    });

    const fireDate = new Date();
    fireDate.setSeconds(fireDate.getSeconds() + 5);

    const trigger: TimestampTrigger = {
      type: TriggerType.TIMESTAMP,
      timestamp: fireDate.getTime(),
      alarmManager: {
        allowWhileIdle: true,
      },
    };

    await notifee.createTriggerNotification(
      {
        title: 'Test Notification',
        body: 'Hello',
        android: {
          channelId,
          badgeIconType: AndroidBadgeIconType.SMALL,
          pressAction: {
            id: 'default',
            launchActivity: 'default',
          },
        },
      },
      trigger,
    );
  } catch (e) {
    console.error(e);
  }
};

const App = () => {
  return (
    <SafeAreaView>
      <TouchableOpacity onPress={testNotification}>
        <Text>RUN</Text>
      </TouchableOpacity>
    </SafeAreaView>
  );
};

export default App;

npx react-native info result:

System:
    OS: macOS 12.4
    CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
    Memory: 1.07 GB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.0/bin/npm
    Watchman: 2022.03.21.00 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /Users/alexandre/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.2 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.0.0 => 18.0.0
    react-native: 0.69.1 => 0.69.1
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

package.json

{
  "name": "notifications",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint . --ext .js,.jsx,.ts,.tsx"
  },
  "dependencies": {
    "@notifee/react-native": "^5.4.0",
    "react": "18.0.0",
    "react-native": "0.69.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "@tsconfig/react-native": "^2.0.0",
    "@types/jest": "^26.0.23",
    "@types/react-native": "^0.69.1",
    "@types/react-test-renderer": "^18.0.0",
    "@typescript-eslint/eslint-plugin": "^5.29.0",
    "@typescript-eslint/parser": "^5.29.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.70.3",
    "react-test-renderer": "18.0.0",
    "typescript": "^4.4.4"
  },
  "resolutions": {
    "@types/react": "^18"
  },
  "jest": {
    "preset": "react-native",
    "moduleFileExtensions": [
      "ts",
      "tsx",
      "js",
      "jsx",
      "json",
      "node"
    ]
  }
}
@dancixx
Copy link

dancixx commented Jul 2, 2022

The same issue is with react-native@0.67.4, but the issue is gone with the previous version on notifee (5.3.0).

@mikehardy
Copy link
Contributor

Do you have the whole stack trace? This is not enough of it to be useful:

[Error: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference]

@alwex
Copy link
Author

alwex commented Jul 2, 2022

@mikehardy here is the stacktrace:

07-03 null:null:null.401 13507 14416 E ReactNativeJS: [Error: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference]
07-03 null:null:null.505 13507 13507 E NOTIFEE : (API): createTriggerNotification
07-03 null:null:null.505 13507 13507 E NOTIFEE : java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at n.o.t.i.f.e.e.o.a(SourceFile:2)
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at app.notifee.core.b.a(SourceFile:130)
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at app.notifee.core.c.a(SourceFile:862)
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at app.notifee.core.c$$ExternalSyntheticLambda5.call(D8$$SyntheticClass)
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at com.google.android.gms.tasks.zzz.run(com.google.android.gms:play-services-tasks@@18.0.null:null:null)
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
07-03 null:null:null.505 13507 13507 E NOTIFEE : 	at java.lang.Thread.run(Thread.java:818)

@mikehardy
Copy link
Contributor

Well that is just bizarre, thanks for the report (great detail by the way), unfortunately the stack trace is a bit uninformative but that's not a complaint, it's just buried in the core library and that's how they look. @helenaford do you have any time for a local repro attempt? I'm travelling and will be for quite some weeks unfortunately. Failing that @alwex you can pull the repo and try to run the core library from source, it's not super hard though a bit subtle. This kind of bug is usually pretty easy to catch with source available though

@alwex
Copy link
Author

alwex commented Jul 2, 2022

I just tried to downgrade to v5.3.0 as @dancixx mentioned and the error is gone. It seems to have been introduced with v5.4.0, so not related with react native. I will try to run the code from source and see what happens.

@helenaford
Copy link
Member

Thanks All, I will look now and find the issue 馃檶

@helenaford
Copy link
Member

Published a fix (v5.4.1), thanks for reporting this! Also, sorry you faced the bug, please let us know if you run into anything else. thanks!

@alwex
Copy link
Author

alwex commented Jul 5, 2022

I confirm the issue is resolved, thank you

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

Successfully merging a pull request may close this issue.

4 participants