[π] When installing the app fresh on some Android devices, onSnapshot does not fire on the first launch. The UI stays stuck on a loading state because the snapshot listener never triggers.
onSnapshot does not fire on first launch after fresh installation on some Android devices
After installing the app fresh via Firebase App Distribution, onSnapshot does not fire on certain Android devices when launching the app for the very first time.
The UI stays stuck in a loading state because the snapshot listener never triggers.
Key points:
- Happens only on Android, and only on first launch after fresh install.
- Works correctly on all iOS devices.
- Works correctly on some Android devices.
-
getDocs()works on all devices, including the affected ones. - If the user kills the app and launches it again, the same affected Android devices work normally β
onSnapshotfires immediately. - Not using Expo.
- Firestore persistence settings are not customized.
- On affected devices,
onSnapshotnever fires even once until the app is killed.
Affected device examples:
- Pixel 9 (Android 15)
- Pixel 6 (Android 12) (others potentially affected)
Code snippet
const db = getFirestore();
const conversationListRef = query(
collection(db, 'xx'),
where('yyy', 'array-contains', xx),
orderBy('updatedAt', 'desc'),
limit(16),
);
const initialSnap = await getDocs(conversationListRef);
unsubscribe = onSnapshot(
conversationListRef,
{ includeMetadataChanges: true },
(snap: FirebaseFirestoreTypes.QuerySnapshot) => {
// execute logic
}
);
return () => {
if (unsubscribe) {
unsubscribe();
}
};
Project Files
Javascript
package.json:
{
"@react-native-async-storage/async-storage": "^2.2.0",
"@react-native-camera-roll/camera-roll": "^7.10.2",
"@react-native-community/datetimepicker": "^8.4.5",
"@react-native-community/netinfo": "^11.4.1",
"@react-native-community/push-notification-ios": "^1.11.0",
"@react-native-firebase/analytics": "^23.4.0",
"@react-native-firebase/app": "^23.4.0",
"@react-native-firebase/auth": "^23.4.0",
"@react-native-firebase/crashlytics": "^23.4.0",
"@react-native-firebase/firestore": "^23.4.0",
"@react-native-firebase/in-app-messaging": "^23.4.0",
"@react-native-firebase/messaging": "^23.4.0",
"react-native": "0.81.5"
}
firebase.json
N/A
iOS
Using Pods.
Podfile
N/A
Android
android/build.gradle
import org.apache.tools.ant.taskdefs.condition.Os
buildscript {
ext {
buildToolsVersion = "35.0.0"
minSdkVersion = 24
compileSdkVersion = 35
targetSdkVersion = 35
ndkVersion = "27.1.12297006"
androidXAnnotation = "1.2.0"
androidXBrowser = "1.3.0"
kotlinVersion = "2.1.20"
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("io.sentry:sentry-android-gradle-plugin:5.12.0")
classpath "com.google.gms:google-services:4.4.4"
classpath "com.google.firebase:firebase-crashlytics-gradle:2.9.2"
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
allprojects {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
maven {
url "$rootDir/../node_modules/detox/Detox-android"
}
}
configurations.all {
resolutionStrategy {
dependencySubstitution { }
}
}
afterEvaluate {
if (tasks.findByName("preBuild")) {
tasks.preBuild.doFirst {
exec {
workingDir rootDir
commandLine './gradlew', 'generateCodegenArtifactsFromSchema'
}
}
println "β app: Will run ./gradlew generateCodegenArtifactsFromSchema before build"
}
}
}
android/app/build.gradle
apply plugin: "com.android.application"
apply plugin: "kotlin-android"
apply plugin: "com.facebook.react"
apply plugin: "com.google.gms.google-services"
apply plugin: "com.google.firebase.crashlytics"
android {
ndkVersion rootProject.ext.ndkVersion
compileSdkVersion rootProject.ext.compileSdkVersion
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
if (project.env.get("ENV_NAME") == "Production") {
signingConfig signingConfigs.release
} else {
signingConfig signingConfigs.debug
}
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
firebaseCrashlytics {
nativeSymbolUploadEnabled true
unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
}
}
}
}
AndroidManifest.xml
N/A
Environment
react-native info
System:
OS: macOS 15.5
CPU: (8) arm64 Apple M1
Memory: 137.67 MB / 16.00 GB
... (full details already provided above)
Platform with the issue:
- [x] Android only
react-native-firebase version:
23.4.0
Firebase module with the issue:
@react-native-firebase/firestore
Using TypeScript:
Yes
It seems like this was an issue in the past, it seems related to https://github.com/invertase/react-native-firebase/issues/2139 Im suspecting it could be a native-sdk issue but I will need to confirm it first.
Thanks for checking this. In my case, I upgraded Firebase library from 17.4.1 to 23.4.0 and React Native from 0.73.9 to 0.81.5. The previous versions were working without any issues.
I will also continue checking on my side to make sure there are no mistakes in the code or configuration with the latest versions.
If you need any additional logs, tests, or device information to verify whether itβs related to #2139 or a native SDK issue, please let me know and I can provide it.
I tried downgrading react-native-firebase to versions 20.5.0 and 19.3.0, but the error wasn't resolved.
When it stays stuck on loading, the error callback also isn't invoked.
The following error appears in BrowserStack's adb log β could this be unrelated?
12-06 12:08:36.130 E/ReactNativeJNI(16184): FabricUIManagerBinding::reportMount: Surface with id -1 is not found 12-06 12:08:40.925 E/GoogleApiManager(16184): Failed to get service from broker. 12-06 12:08:40.925 E/GoogleApiManager(16184): java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'. 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Parcel.createExceptionOrNull(Parcel.java:3242) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Parcel.createException(Parcel.java:3226) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Parcel.readException(Parcel.java:3209) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Parcel.readException(Parcel.java:3151) 12-06 12:08:40.925 E/GoogleApiManager(16184): at bckw.a(:com.google.android.gms@[email protected] (260400-833691957):36) 12-06 12:08:40.925 E/GoogleApiManager(16184): at bcix.z(:com.google.android.gms@[email protected] (260400-833691957):143) 12-06 12:08:40.925 E/GoogleApiManager(16184): at bbpa.run(:com.google.android.gms@[email protected] (260400-833691957):42) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Handler.handleCallback(Handler.java:959) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Handler.dispatchMessage(Handler.java:100) 12-06 12:08:40.925 E/GoogleApiManager(16184): at cpny.ms(:com.google.android.gms@[email protected] (260400-833691957):1) 12-06 12:08:40.925 E/GoogleApiManager(16184): at cpny.dispatchMessage(:com.google.android.gms@[email protected] (260400-833691957):5) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Looper.loopOnce(Looper.java:232) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.Looper.loop(Looper.java:317) 12-06 12:08:40.925 E/GoogleApiManager(16184): at android.os.HandlerThread.run(HandlerThread.java:85)