-
Notifications
You must be signed in to change notification settings - Fork 2.3k
No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp() on Android despite correct setup #7462
-
React Native 0.71.3 + Typescript. Project uses ProGuard too, apparently.
I'm trying to integrade push notifications through cloud messaging. I've only tested it on Android.
I did all the steps required. What am I missing?
- npm install --save @react-native-firebase/app
- placed my google-services.json file in /android/app/ folder
- Added
classpath 'com.google.gms:google-services:4.4.0'at/android/build.gradle - Added apply plugin:
'com.google.gms.google-services'at /android/app/build.gradle - npm install @react-native-firebase/messaging
- npx react-native run-android to rebuild the project
7)import messaging from '@react-native-firebase/messaging';in my App.tsx - For testing, I'm adding this function from the documentation
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
}
- I call the function inside an useEffect() in App.tsx
Yet, despite all these steps, I keep getting
Possible Unhandled Promise Rejection (id: 0):
Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()
What am I missing? This is driving me insane.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 7
Reproduced. On rn71 stock templates if you use google-services 4.4.0 it fails on android in exactly the way you describe
If you use rn71 you must use google-services 4.3.15 - it works fine
If you use rn72 you may update to google-services 4.4.0 - it works fine
I'll post a note in the install documentation
Thanks for noticing this!
Replies: 18 comments 25 replies
-
Hey there 👋 - there must be some steps after step 9? Like "then I run the pod install / build for whatever platform etc" ? I'm not sure which platform the problem is on so I can't say what those commands should be but if you specify what you do I may be able to help more.
Alternatively you can have a quick read through the comments on my "build a firebase app from scratch, start to finish in one script" script where I demonstrate how to do the integration: https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi. I'm having the same issue, which has also drove me insane, well almost. ;-). My findings so far:
- In my case, the
NATIVE_FIREBASE_APPSarray of theRNFBAppModuleNative Module seems to be empty on Android. On iOS, this array contains 1 element, which is a reference to the Firebase App on the native side. On Android, this array is filled in thegetConstantsmethod of theReactNativeFirebaseAppModule(contained in the @react-native-firebase/app package). - To research the issue further, I have set up 2 basic React Native projects (using the
npx react-native initcommand). One project uses RN version 0.71.13 and the other version 0.72.7. To both projects, I have added the latest @react-native-firebase/app package (18.6.1) and added the google services gradle plugin and the google services json file. On the 0.72.7 version, everything works as expected and on the 0.71.13 version the same error is seen. - The Google Services grade plugin should parse the google services json file and create 1 (or 2?) xml files (see
android/app/build/generated/res/) that are then used at runtime to initialize the Firebase objects. In the 0.71.13 project, these files are not created while on the 0.72.7 version, these are correctly created.
I suspect that there is some version incompatibility issue between Gradle and the Google Services gradle plugin.
Beta Was this translation helpful? Give feedback.
All reactions
-
@sander48k very interesting finding. rn71 certainly worked when I was build-testing while it was out
At the time the google-services plugin version was 4.3.15 - have you tried that one in combination with react-native 0.71.x ?
I've branched my reproducible build-test repo at the commit where rn71 was last used (implying it uses google services plugin 4.3.15, not current / 4.4.0),
I'm running a build test now https://github.com/mikehardy/rnfbdemo/blob/rn71/make-demo.sh but may run out of time today before I can report more results.
It does seem that upgrading to react-native 0.72 is a obvious pathway to success here though :-)
Beta Was this translation helpful? Give feedback.
All reactions
-
Reproduced. On rn71 stock templates if you use google-services 4.4.0 it fails on android in exactly the way you describe
If you use rn71 you must use google-services 4.3.15 - it works fine
If you use rn72 you may update to google-services 4.4.0 - it works fine
I'll post a note in the install documentation
Thanks for noticing this!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 33 -
❤️ 11
-
Thanks Mike! Good to know that version 4.3.15 works with my rn71 project!
Beta Was this translation helpful? Give feedback.
All reactions
-
I am using this configuration and tried both the google-service version but Its not working for me.
"react-native": "0.72.7",
classpath 'com.google.gms:google-services:4.3.15'
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 4
-
I am also facing the same issue
Beta Was this translation helpful? Give feedback.
All reactions
-
I am also facing the same issue. @mikehardy
Beta Was this translation helpful? Give feedback.
All reactions
-
in my case, another problem was that i had missed the step 4 which @DragomirAndrei19 mentioned:
"Added apply plugin: 'com.google.gms.google-services' at /android/app/build.gradle"
(it's just one line in the documentation and i had missed it! took me a day to figure that out😑)
anyway I ended up using RN 0.72.6 and com.google.gms:google-services:4.4.0.
Beta Was this translation helpful? Give feedback.
All reactions
-
thank you its worked. its my saved day :)
Beta Was this translation helpful? Give feedback.
All reactions
-
Should be 4.4.2 now though :-), cheers
https://firebase.google.com/support/release-notes/android (all versions are listed there, our docs should have the versions up to date as well)
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @mikehardy
No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()
RN 0.73.6
gradle version 8
classpath 'com.google.gms:google-services:4.4.1'
Beta Was this translation helpful? Give feedback.
All reactions
-
@zocial-rajesh --> does not reproduce: https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh
You might examine the output of that from-scratch successful-build reproducer and see if you can find the difference in your gradle files, that should get you going
Beta Was this translation helpful? Give feedback.
All reactions
-
I have same issue in RN latest version:
(NOBRIDGE) ERROR Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()
"react-native": "0.74.0"
classpath("com.google.gms:google-services:4.4.1")
Beta Was this translation helpful? Give feedback.
All reactions
-
👀 6
-
Same issue on react native 0.74
(NOBRIDGE) ERROR Error: No Firebase App '[DEFAULT]' has been created - call firebase.initializeApp()
"react-native": "0.74.0"
classpath("com.google.gms:google-services:4.4.1")
Beta Was this translation helpful? Give feedback.
All reactions
-
👀 4
-
You need to configure crashlytics(or any other firebase services which u want) separately after configuring firebase https://rnfirebase.io/crashlytics/usage
There are some additional steps here.
Beta Was this translation helpful? Give feedback.
All reactions
-
the fix for react-native 0.74
Beta Was this translation helpful? Give feedback.
All reactions
-
Does anybody know why I get this error?
Plugin with id 'com.google.gms.google-service' not found
Beta Was this translation helpful? Give feedback.
All reactions
-
Maybe you forgot to add the plugin in your app/build.gradle?
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm using Expo and using typescript. In my case plugins were not working so I had to go with React Native CLI - Android Setup instead of Expo.
"react-native": "0.74.3"
"expo": "^51.0.21"
"@react-native-firebase/app": "^20.3.0"
"@react-native-firebase/messaging": "^20.3.0"
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm using Expo and using typescript. In my case plugins were not working so I had to go with React Native CLI - Android Setup instead of Expo.
React Native CLI - Android Setup documentation for expo solved my issue
adding in app.json :
"plugins": [
"@react-native-firebase/app",
"@react-native-firebase/messaging"
]
solved the "call firebase.InitializeApp()" issue,
still didn't get the notification so i added the permission of expo-notifications and it's working now...
Beta Was this translation helpful? Give feedback.
All reactions
-
Adding the plugins to app.json worked (I'm running RN 0.74.5) but I also had to run npx expo prebuild --clean before it would add the com.google.gms:google-services:4.4.1 line to my build.gradle.
Beta Was this translation helpful? Give feedback.
All reactions
-
Double-check if apply plugin: 'com.google.gms.google-services' is added inside build.gradle located inside android/app folder
Ref: #7788 (comment)
Beta Was this translation helpful? Give feedback.
All reactions
-
I forgot to add my iOS credentials to AppDelegate.m, and that I have it works!
Check out items 2 and 3 here: https://rnfirebase.io/
Beta Was this translation helpful? Give feedback.
All reactions
-
I resolved the issue by updating the package.json dependencies for Firebase:
"dependencies": {
"@react-native-firebase/app": "^21.3.0",
"@react-native-firebase/messaging": "^21.3.0"
}
I found the latest compatible versions on the npm website.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2 -
🎉 4
-
I resolved the issue by updating the package.json dependencies for Firebase:
"dependencies": { "@react-native-firebase/app": "^21.3.0", "@react-native-firebase/messaging": "^21.3.0" }I found the latest compatible versions on the npm website.
This solution worked for me! I had to update all my firebase dependencies and I'm using the following versions:
- RN: 0.76.1;
- @react-native-firebase/app: 21.5.0;
Beta Was this translation helpful? Give feedback.
All reactions
-
"@react-native-firebase/app": "^21.3.0",
"@react-native-firebase/messaging": "^21.3.0"
it worked for me
Beta Was this translation helpful? Give feedback.
All reactions
-
This works for me
"react-native": "0.76.6",
"@react-native-firebase/app": "21.3.0",
Beta Was this translation helpful? Give feedback.
All reactions
-
Tried to fix it with the following setup:
Dependencies Tried:
"react-native": "0.75.4",
"expo": "^51.0.31",
"@react-native-firebase/app": "^21.3.0" AND "^21.6.1"
"@react-native-firebase/messaging": "^21.3.0" AND "^21.6.1",
Different try:
"expo": "^52.0.11" with
"react-native": "0.76.3"
react-native failed to have compatibility for aws/amplify UI, so didn't get to check if it was working with Firebase.
Beta Was this translation helpful? Give feedback.
All reactions
-
@KLichtenauer
https://stackoverflow.com/help/minimal-reproducible-example
https://stackoverflow.com/help/how-to-ask
starter https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh
Beta Was this translation helpful? Give feedback.
All reactions
-
@mikehardy i am facing same issue on android and ios. i have checked the confirguration multiple times and its correct also google-service.json and GoogleService-Info.plist is placed in correct directory. Here is my version of firebase and react native
"@react-native-firebase/app": "21.10.1",
"@react-native-firebase/messaging": "21.10.1",
"react": "18.3.1",
"react-native": "0.76.9",
Beta Was this translation helpful? Give feedback.
All reactions
-
So, you are on an old react-native, you likely need google-services gradle plugin 4.3.15, as indicated above @Muhammadmahadsaeed
What version of that plugin are you using?
Beta Was this translation helpful? Give feedback.
All reactions
-
@mikehardy i am using this classpath 'com.google.gms:google-services:4.4.2' and also tried with 4.3.15 but still facing same issue on android and ios
Beta Was this translation helpful? Give feedback.
All reactions
-
I got that error after upgrading React Native from 0.72 to 0.77 version
New Arch: disabled
Hermes: disabled
Firebase: 12.9.3
My fix in android/build.gradle
- classpath 'com.google.gms:google-services:4.3.10' + classpath 'com.google.gms:google-services:4.4.3'
I hope it will help someone
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 3
-
The solution for me was to revert to the old value for newArchEnabled=false, upgrading react-native sets this value to true, which causes problems.
Beta Was this translation helpful? Give feedback.
All reactions
-
🚀 2
-
Same issue, I am using "@react-native-firebase/app": "^23.3.0"
Beta Was this translation helpful? Give feedback.
All reactions
-
getting the same error when trying to run on android. using react-native : 0.81.4. using version 23.3.1 for my firebase packages. using version 4.4.3 for google services.
Beta Was this translation helpful? Give feedback.