I have developed a flutter app based on firebase. Now I would like to be able to use the emulator environment of firebase for development. To do this, I have installed and set up the emulator with all the necessary dependencies. However, when I now want to run the Flutter app on my mobile phone (which is on the same internet as my PC) I get the following error:
W/Firestore( 4188): (24.11.0) [WatchStream]: (741277b) Stream closed with status: Status{code=UNAVAILABLE, description=null, cause=java.net.ConnectException: failed to connect to /192.168.178.69 (port 8080) from /:: (port 41652): connect failed: ECONNREFUSED (Connection refused)
W/Firestore( 4188): at libcore.io.IoBridge.connect(IoBridge.java:187)
W/Firestore( 4188): at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
W/Firestore( 4188): at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
W/Firestore( 4188): at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
W/Firestore( 4188): at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
W/Firestore( 4188): at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
W/Firestore( 4188): at java.net.Socket.connect(Socket.java:646)
W/Firestore( 4188): at java.net.Socket.connect(Socket.java:595)
W/Firestore( 4188): at java.net.Socket.<init>(Socket.java:475)
W/Firestore( 4188): at java.net.Socket.<init>(Socket.java:275)
W/Firestore( 4188): at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:285)
W/Firestore( 4188): at io.grpc.okhttp.OkHttpClientTransport$3.run(OkHttpClientTransport.java:535)
W/Firestore( 4188): at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
W/Firestore( 4188): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
W/Firestore( 4188): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
W/Firestore( 4188): at java.lang.Thread.run(Thread.java:1012)
The Firestore emulator ist running on Port 8080
How can I fix this error?
I have chosen the following setup:
my main:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
if (kDebugMode) {
try{
//I Know for sure that this is the real local ip of my PC
FirebaseFirestore.instance.useFirestoreEmulator('192.168.178.69', 8080);
await FirebaseAuth.instance.useAuthEmulator('192.168.178.69', 9099);
} catch (e) {
print("Could not connect to emulator");
}
}
await FirebaseAppCheck.instance.activate(
androidProvider: AndroidProvider.debug,
);
runApp(ProviderScope(child: MyApp()));
}
my firebase.json:
{
"emulators": {
"singleProjectMode": true,
"auth": {
"host": "0.0.0.0",
"port": 9099
},
"firestore": {
"host": "0.0.0.0",
"port": 8080
},
"storage": {
"host": "0.0.0.0",
"port": 9199
},
"ui": {
"enabled": true,
"port": 4000
}
},
"storage": {
"rules": "storage.rules"
}
}