Firebase 에뮬레이터 FireStore 연결 오류
에러 내용
2022-03-02 11:56:27.571 366-366/? E/android.hardware.power.stats@1.0-service-mock: Failed to getEnergyData
2022-03-02 11:56:27.646 8626-8684/com.healthyryu.app.debug W/Firestore: (23.0.4) [WriteStream]: (be2386) Stream closed with status: Status{code=UNAVAILABLE, description=null, cause=java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 8080) from /:: (port 53300): connect failed: ECONNREFUSED (Connection refused)
at libcore.io.IoBridge.connect(IoBridge.java:188)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at java.net.Socket.connect(Socket.java:570)
at java.net.Socket.<init>(Socket.java:450)
at java.net.Socket.<init>(Socket.java:250)
at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:285)
at io.grpc.okhttp.OkHttpClientTransport$4.run(OkHttpClientTransport.java:555)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
at libcore.io.Linux.connect(Native Method)
at libcore.io.ForwardingOs.connect(ForwardingOs.java:204)
at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:157)
at libcore.io.ForwardingOs.connect(ForwardingOs.java:204)
at libcore.io.IoBridge.connectErrno(IoBridge.java:202)
at libcore.io.IoBridge.connect(IoBridge.java:180)
at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
at java.net.Socket.connect(Socket.java:621)
at java.net.Socket.connect(Socket.java:570)
at java.net.Socket.<init>(Socket.java:450)
at java.net.Socket.<init>(Socket.java:250)
at javax.net.DefaultSocketFactory.createSocket(SocketFactory.java:285)
at io.grpc.okhttp.OkHttpClientTransport$4.run(OkHttpClientTransport.java:555)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:920)
}.
자체 PC or Mac 에서 로컬로 Firebase Emulator 실행해서 FireStore 를 테스트할 경우 Android 에서는 다음과 같이 usetEmulaotr 를 해줘야 한다.
FirebaseFirestore firestore = FirebaseFirestore.getInstance();
firestore.useEmulator("10.0.0.2", 8080);
FirebaseFirestoreSettings settings = new FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(false)
.build();
firestore.setFirestoreSettings(settings);
참고 링크
여기서 Android 앱에서 host 입력하는 부분에는 loccalhost 를 입력할 경우 이 localhost 는 안드로이드 앱 내부의 localhost 를 의미하지 PC or Mac 의 localhost 를 의미하지 않는다. 그렇기에 10.0.2.2 를 입력해주어야 한다.
반응형
'Dev > Android' 카테고리의 다른 글
[Android] 꺼진 화면 켜기 (0) | 2022.03.24 |
---|---|
Android 폰에 GMS 가 없다니?! (0) | 2022.03.04 |
Android Gradle 빌드파일 - build.gradle.kts 참고 (0) | 2021.07.13 |
[UI/UX] 서비스마다 제각각인 비밀번호 텍스트 창 (0) | 2021.07.06 |
AndroidX 로 바뀌면서 Activity, Fragment 에 유용한 작업 기능 (0) | 2021.06.29 |