question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firebase Auth crashes with OutOfMemoryError in Android 12

See original GitHub issue

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: Bumblebee 2021.1.1 Patch 2
  • Firebase Component: auth
  • Component version: firebase-auth:21.0.3
  • Device: Android 12 - Samsung S10

[REQUIRED] Step 3: Describe the problem

Firebase Auth crashes with OutOfMemoryError in Android 12

Steps to reproduce:

This is the console output for one of our Android 12 users getting the crash.

java.lang.OutOfMemoryError: Failed to allocate a 150994952 byte allocation with 25165824 free bytes and 104MB until OOM, target footprint 452092968, growth limit 536870912 at java.util.Arrays.copyOf(Arrays.java:3257) at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124) at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:649) at java.lang.StringBuilder.append(StringBuilder.java:203) at org.json.JSONStringer.string(JSONStringer.java:327) at org.json.JSONStringer.value(JSONStringer.java:261) at org.json.JSONArray.writeTo(JSONArray.java:616) at org.json.JSONStringer.value(JSONStringer.java:242) at org.json.JSONObject.writeTo(JSONObject.java:740) at org.json.JSONObject.toString(JSONObject.java:708) at com.google.firebase.auth.internal.zzbg.zzd(com.google.firebase:firebase-auth@@21.0.3:27) at com.google.firebase.auth.FirebaseAuth.zzH(com.google.firebase:firebase-auth@@21.0.3:13) at com.google.firebase.auth.zzo.zza(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzrv.zzb(com.google.firebase:firebase-auth@@21.0.3:3) at com.google.android.gms.internal.firebase-auth-api.zzuh.zzj(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzue.zzn(com.google.firebase:firebase-auth@@21.0.3:2) at com.google.android.gms.internal.firebase-auth-api.zztg.zzn(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzqe.zzb(com.google.firebase:firebase-auth@@21.0.3:2) at com.google.android.gms.internal.firebase-auth-api.zzup.zza(com.google.firebase:firebase-auth@@21.0.3:24) at com.google.android.gms.internal.firebase-auth-api.zztv.zzf(com.google.firebase:firebase-auth@@21.0.3:4) at com.google.android.gms.internal.firebase-auth-api.zzrl.zzp(com.google.firebase:firebase-auth@@21.0.3:4) at com.google.android.gms.internal.firebase-auth-api.zzth.zzj(com.google.firebase:firebase-auth@@21.0.3:5) at com.google.android.gms.internal.firebase-auth-api.zzrv.zzc(com.google.firebase:firebase-auth@@21.0.3:1) at com.google.android.gms.internal.firebase-auth-api.zzui.run(com.google.firebase:firebase-auth@@21.0.3:1) 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)

Relevant Code:

It calls this code when resuming the app and crashes.

fun checkSignedIn(isPhoneAuth: Boolean) {
        if (!isPhoneAuth) {
            val fireBaseUser = FirebaseAuth.getInstance().currentUser

            fireBaseUser?.let { user ->

                user.getIdToken(true)
                        .addOnCompleteListener { task ->
                            if (task.isSuccessful) {
                                task.result?.token?.let { token ->
                                    if (loggingIn) {
                                        login(token, LoginMethod.FACEBOOK)
                                    } else {
                                        signup(token, LoginMethod.FACEBOOK)
                                    }
                                } ?: kotlin.run {
                                    resetLogin()
                                }
                            } else {
                                resetLogin()
                                val exception = task.exception
                                val errorMessage = exception?.message ?: ""

                                onError(errorMessage)
                            }
                        }
            } ?: kotlin.run {
                if (!isLoading) {
                    showLogin()
                }
            }
        } else {

            val fireBaseUser = FirebaseAuth.getInstance().currentUser

            fireBaseUser?.let { user ->

                user.getIdToken(true)
                        .addOnCompleteListener { task ->
                            if (task.isSuccessful) {
                                task.result?.token?.let { token ->
                                    saveAccessToken(token)
                                    phoneAuthAccessToken = token

                                    if (loggingIn) {
                                        login(phoneAuthAccessToken, LoginMethod.PHONE)
                                    } else {
                                        signup(phoneAuthAccessToken, LoginMethod.PHONE)
                                    }
                                } ?: kotlin.run {
                                    resetLogin()
                                }
                            } else {
                                resetLogin()
                                val exception = task.exception
                                val errorMessage = exception?.message ?: ""

                                onError(errorMessage)
                            }
                        }
            } ?: kotlin.run {
                //resetLogin()
                if (!isLoading) {
                    showLogin()
                }
            }
        }
    }

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:27
  • Comments:43 (5 by maintainers)

github_iconTop GitHub Comments

22reactions
rosalyntancommented, Jun 14, 2022

Hi @Cellaryllis – a fix for both the NPE and OOM will be going out in the next release. However, this issue has proven extremely hard to reproduce, so we’ve been unable to fully verify if the OOM is resolved, unfortunately.

I’ll update this thread again once the new version is released.

15reactions
rosalyntancommented, May 31, 2022

Hi folks, thanks for reporting this issue! As an update, we’re currently working on verifying a fix for this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Application crashes at Uncaught exception in ...
The exception you get is OutOfMemoryError . This means that you're trying to download more data from the database than your device has...
Read more >
Firebase Android SDK Release Notes - Google
Authentication version 21.0.6. Fixed a NullPointerException crash. Addressed a potential cause of an OutOfMemoryError crash.
Read more >
Apparyllis on Twitter: "In the meantime, you can use our web version ...
This is due to a dependency from Google (Firebase) causing the crash. ... Firebase Auth crashes with OutOfMemoryError in Android 12 · Issue...
Read more >
How Does OutOfMemory Error Happen and How to Solve it in ...
When you run an application on an Android device, the Android system allocates memory to it in order for it to function. All...
Read more >
Crashes | Android Developers
There are many situations that can cause a crash in your app. Some reasons are obvious, like checking for a null value or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found