Local Notifications only not compiling on Android
See original GitHub issueSolution
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
npx react-native run-android
Describe what you expected to happen:
- App built on emulator
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:8
Top GitHub Comments
Changing the implementation from
implementation 'com.google.firebase:firebase-messaging:20.2.4'
toinside the plugin build.gradle fixes the problem
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 }