I keep getting this error message while I try to run my ionic app on my android devices.
Most of the question avaiable with same message has permission denied but in my case its [code=unavailable]
@firebase/firestore: Firestore (10.8.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: The operation could not be completed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
I really have fast internet connection and not sure why this appear. There were issue with ios as well but I have manage to fixed with some condition. But for android its not working with any of the condition.
I am using Ionic Angular 17 with firebase.
my app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { AppComponent } from './app.component';
import { environment } from 'environments/environment';
import { AppRoutingModule } from './app-routing.module';
import { QuillModule, provideQuillConfig } from 'ngx-quill';
import { provideFirestore } from '@angular/fire/firestore';
import { getFirestore, initializeFirestore } from 'firebase/firestore';
import { provideAuth } from '@angular/fire/auth';
import { initializeApp, getApp } from "firebase/app";
import {provideFirebaseApp} from "@angular/fire/app";
import { Capacitor } from "@capacitor/core";
import { getAuth, initializeAuth, indexedDBLocalPersistence } from "firebase/auth"
import { HttpClientModule } from '@angular/common/http';
const app = initializeApp(environment.firebase);
const firestoreDB = initializeFirestore(getApp(), {
experimentalAutoDetectLongPolling: true
})
// TODO comment for ios app
// const auth = getAuth(app);
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpClientModule,
// provideFirebaseApp(() => initializeApp(environment.firebase)),
// provideFirestore(() => getFirestore()),
provideFirestore(() => {
if (Capacitor.isNativePlatform()) {
return firestoreDB
} else {
return getFirestore();
}
}),
provideAuth(() => {
if (Capacitor.isNativePlatform()) {
return initializeAuth(getApp(), {
persistence: indexedDBLocalPersistence
})
} else {
return getAuth(app);
}
}),
// TODO comment for ios app
// provideAuth(() => auth),
QuillModule.forRoot({
modules: {
syntax: false,
toolbar: {
container: [
[{ align: [] }],
["bold", "italic", "underline", "strike"],
["link"],
[{ list: "ordered" }, { list: "bullet" }],
[{ color: [] }, { background: [] }],
],
}
},
}),
],
providers: [{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
export class AppModule {}