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.

Local Notifications only not compiling on Android

See original GitHub issue

Solution

I tried what @qasim483 said to do, and it worked for me. Here’s the solution that fixed my problem with the addition of simply 2 lines of code (1 in each file)

android/app/build.gradle

android {
   ...
   dependencies {
      ...
      implementation 'com.google.firebase:firebase-messaging:21.1.0'
   }
}

android/build.gradle

buildscript {
   ext {
      ...
      firebaseMessagingVersion = "21.1.0"
   }
}

Bug

So I’ve used react-native-push-notification for probably 3 or 4 years now, local notifications only, with no problem. But for some reason, I can’t compile my project on Android anymore. I’m receiving an error due to firebase it looks like, but I don’t use firebase. I’m not sure - is Firebase a new requirement? I’ve tried some of the steps like adding classpath('com.google.gms:google-services:4.3.3') to build.gradle, but then it gets into making me sign up for Firebase. I just built a release version of my app about a week ago, so I’m not sure why I am suddenly being asked about Firebase. I haven’t added anything from npm and it started crashing. Though today, I did upgrade from I think 7.1.0 to the latest version of react-native-push-notification: 7.2.3, hoping it would work.

Environment info

System: OS: macOS 11.1 CPU: (16) x64 Intel® Core™ i9-9880H CPU @ 2.30GHz Memory: 7.25 GB / 32.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 12.14.1 - /usr/local/bin/node Yarn: Not Found npm: 7.5.2 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.10.1 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 14.3, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2 Android SDK: API Levels: 23, 27, 28, 29, 30 Build Tools: 28.0.3, 29.0.2 System Images: android-28 | Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google Play Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: 4.1 AI-201.8743.12.41.7042882 Xcode: 12.3/12C33 - /usr/bin/xcodebuild Languages: Java: 1.8.0_242 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: ^17.0.1 => 17.0.1 react-native: ^0.64.0 => 0.64.0 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

react-native info output:

> Task :react-native-push-notification:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings
449 actionable tasks: 5 executed, 444 up-to-date
/Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:39: error: cannot find symbol
import com.google.firebase.iid.FirebaseInstanceId;
                              ^
  symbol:   class FirebaseInstanceId
  location: package com.google.firebase.iid
/Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:40: error: cannot find symbol
import com.google.firebase.iid.InstanceIdResult;
                              ^
  symbol:   class InstanceIdResult
  location: package com.google.firebase.iid
/Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:143: error: cannot find symbol
              .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                                                            ^
  symbol:   class InstanceIdResult
  location: class RNPushNotification
/Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:145: error: cannot find symbol
                  public void onComplete(@NonNull Task<InstanceIdResult> task) {
                                                       ^
  symbol: class InstanceIdResult
/Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:142: error: cannot find symbol
      FirebaseInstanceId.getInstance().getInstanceId()
      ^
  symbol:   variable FirebaseInstanceId
  location: class RNPushNotification
/Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java:289: error: cannot find symbol
                  FirebaseInstanceId.getInstance().deleteInstanceId();
                  ^
  symbol: variable FirebaseInstanceId
Note: /Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/macbook-pro/Desktop/repos.nosync/DBT2/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors

FAILURE: Build failed with an exception.

Library version: 7.2.3

Steps To Reproduce

  1. npx react-native run-android

Describe what you expected to happen:

  1. App built on emulator

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:8

github_iconTop GitHub Comments

2reactions
mtb77commented, May 11, 2021

Changing the implementation from implementation 'com.google.firebase:firebase-messaging:20.2.4' to

implementation platform('com.google.firebase:firebase-bom:26.8.0')
implementation 'com.google.firebase:firebase-messaging'

inside the plugin build.gradle fixes the problem

1reaction
qasim483commented, May 11, 2021

In app build.gradle: implementation ‘com.google.firebase:firebase-messaging:21.1.0’

in android build.gradle: ext { firebaseMessagingVersion = “21.1.0” buildToolsVersion = “29.0.2” minSdkVersion = 24 compileSdkVersion = 29 targetSdkVersion = 29 }

this worked for me.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Notifications Not Showing Up? 10 Fixes You Can Try
Android Notifications Not Showing Up? 10 Fixes You Can Try · 1. Reboot Your Phone · 2. Review the App's Notification Settings ·...
Read more >
Error while compiling after i installed @capacitor/local ...
npm install @capacitor/local-notifications. but when i tried to run the ionic aplication in emulator android studio, i got this error.
Read more >
[Local Notifications Plugin] Notifications not showing on Android
I tried to use this plugin but, although notifications are showing as expected on iOS, they don't show on Android (8.1.0)? Anyone with...
Read more >
flutter_local_notifications | Flutter Package - Pub.dev
A cross platform plugin for displaying and scheduling local notifications for Flutter ... Token is not supported, with this style you let Android...
Read more >
Create a Notification - Android Developers
Create the NotificationChannel, but only on API 26+ because // the NotificationChannel class is new and not in the support library if (Build.VERSION....
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