question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

šŸ› android alarm manager error with react native >= 0.68

See original GitHub issue

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"
    ]
  }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alwexcommented, 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.

1reaction
mikehardycommented, Jul 2, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

null is not an object (evaluating '_reactNativeAlarmManager ...
When I install react-native-alarm-manager ... Even after editing it, I get the error TypeError: null is not an object (evaluatingĀ ...
Read more >
Blog - React Native
Hello everyone! Today we are announcing the 0.68.0 release of React Native, with opt-in to the New React Native Architecture, bug fixes and...
Read more >
react-native-alarm-manager - npm
Start using react-native-alarm-manager in your project by running `npm i react-native-alarm-manager`. There are no other projects in the npmĀ ...
Read more >
launchdarkly-react-native-client-sdk | Yarn - Package Manager
Fixed: Android: Fixed an issue where the jsonVariationDetail method in LDClient returned Promise<Record<string, any>> instead of the declared return type ofĀ ...
Read more >
Bug listing with status RESOLVED with resolution TEST ...
Error in sched.c line 961." status:RESOLVED resolution:TEST-REQUEST severity:major Ā· Bug:22815 - "Gentoo fails to reboot after changes are made to theĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found