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:
- Created a year ago
- Reactions:27
- Comments:43 (5 by maintainers)
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.
Hi folks, thanks for reporting this issue! As an update, we’re currently working on verifying a fix for this issue.