Firebase doesn't work on Android Studio Emulator
Asked Answered
W

9

19

I was working on a project for my studies and everything was working fine, but I changed my OS to win11 while wiping all previous data.
Now Firebase is stuck on "loading" after using any type of sign in. Real time database data is not showing as well. After around 5-10 of waiting auth will sometimes work continuously (can sign in, sign out multiple times, until running app again) but database never.
Everything works well when i use physical device. Apps without firebase work fine on emulator. Internet connection works. Example app that doesn't work:
https://github.com/firebase/quickstart-android

I have:

  1. Used multiple different emulators(those with google play) with different sdk
  2. Changed SHA1 and google-servies.json
  3. In Settings -> Appearance & Behavior -> SDK Tools downloaded and activated Google play service
  4. Reinstalling Android Studio, installing win10 again
  5. Updated Google Play services version
  6. Tried different projects on different firebase accounts
  7. Activated Sign-in methods in firebase console
  8. Searched web for several hours and done many other things I can't even remember now

The only error I'm sometimes getting is:
E/FirebaseInstanceId: binding to the service failed
and this error when I use new emulator for the first time:
E/FirebaseMessaging: Topic sync or token retrieval failed on hard failure exceptions: java.util.concurrent.ExecutionException: java.io.IOException: AUTHENTICATION_FAILED. Won't retry the operation.
E/FirebaseInstanceId: Topic sync or token retrieval failed on hard failure exceptions: AUTHENTICATION_FAILED. Won't retry the operation.
E/FA: Missing google_app_id. Firebase Analytics disabled.
E/FA: Uploading is not possible. App measurement disabled

For me it looks like something is blocking(or really slowing down) connection between android studio emulator and firebase.
I would be very grateful for any kind of help, its really important for my studies.

Waves answered 16/8, 2022 at 8:8 Comment(0)
W
19

What fixed my problem was installing an older version of android emulator form this website:
https://developer.android.com/studio/emulator_archive
I was using Android Emulator (31.3.10) Beta 1 and switching to Android Emulator (30.9.5) solved the problem.

Waves answered 17/8, 2022 at 22:23 Comment(0)
S
11

I think it's the emulator... Or at least it was for me. I was working with version 31.3.10 and had the same problem. App would not connect to the Firebase server in the emulator. Firebase Authentication would eventually work but took forever to login. Firebase was only using local data. Queries to Firebase returned results only from the cache (which was empty anyway), and I could see that (QuerySnapshot.metadata.isFromCache was true). Tried reinstalling the app, deleted the emulator image and made a new one, nothing worked. Internet access on the emulator was fine, I could browse web pages etc. Only thing that worked was downgrading the emulator. I went back to 31.2.10, cause I knew that one worked. You can get older versions from https://developer.android.com/studio/emulator_archive

I really hope they fix it soon cause it cost me a whole day to figure out wtf. Hope this helps someone else.

Shorten answered 2/9, 2022 at 14:50 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Endarch
Thank you it worked when downloaded 31.2.10Yehudi
J
9

I have the same problem. It happened after several updates: Windows and Android Studio. Apparently, it's the emulator (version 31.3.10).

In my case, the solution to the problem is disabling Wi-Fi in the emulator and enabling mobile Internet. Although in fact the connection in Windows remains the same.

Jaala answered 28/8, 2022 at 3:37 Comment(1)
In order to get Firebase RTDB to sync from a virtual device, I had to downgrade my emulator to 31.2.10 and create a virtual device that runs Android 11.0 (API 30). API 31, 32, and 33 wouldn't sync to RTDB. Also, in the virtual device settings, I had to disable Wi-Fi and enable mobile internet. When I did only one of those three things (downgrade the emulator, use Android 11.0, or disable Wi-Fi), Firebase RTDB would not sync from the virtual device.Carberry
B
3

I found the solution here. Error in the emulator version 31.3.10. Change the emulator to 30.2.9 https://youtu.be/qo3SbdbXFos

Bavardage answered 18/9, 2022 at 10:41 Comment(2)
Having a lot of problems with that version of emulator after updating android studio to dolphin releasePinard
I upgraded mine to 31.3.11 and it started to workPara
K
3

I was using emulator version something like 31.3.10 and upgraded it to 31.3.11. Now problem is solved. Downgrading will also work but i like upgrading.

Below i have attached the screenshot:

https://user-images.githubusercontent.com/96950460/193184898-28e24140-8b12-4c80-8900-c56d4776619b.png

Kelsi answered 30/9, 2022 at 3:42 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewDee
P
2

The problem seems to be the emulator. I updated android studio recently and the code that I had already gotten to speak to firebase stopped working without me editing anything.

Instead of reverting to an older emulator, I switched to using a physical device such as my phone instead.

It fixed it right away.

Parabola answered 29/9, 2022 at 19:56 Comment(0)
C
0

I have the same issue with emulator 31.3.12. After app startup it can't connect to any Firebase services. After 7 minutes and several retries it worked. Without any interaction from my side.

I am using Firebase Remote Config and Crashlytics.

enter image description here

Cyrano answered 15/10, 2022 at 12:57 Comment(1)
Same issue also with 31.3.13Desexualize
T
0

In my case the solution was to set usesCleartextTraffic to true in AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>
Testate answered 25/4, 2023 at 11:7 Comment(0)
M
0

Here is how I resolved this issue.

  1. Turn-on the airplane mode
  2. Turn-off the airplane mode
  3. Turn-off WiFi
  4. Turn-off mobile data
  5. Turn-on mobile data

Hope it could help resolving your issue.

Maurinemaurise answered 8/7 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.