Today's

길을 나서지 않으면 그 길에서 만날 수 있는 사람을 만날 수 없다

모바일 앱(안드로이드)

안드로이드 앱 만들기 : Firebase Auth crash when AGP 8.0

Billcorea 2023. 5. 8. 23:54
반응형

안드로이드 gradle 이 8.0.x로 넘어가면서 발생한 이슈에 대한 이야기를 적어 두고자 합니다. 

앱을 구현하는 동안에 firebase의 사용자 인증을 사용하고자 했으나, 이것이 인증 오류를 발생시키게 됩니다. 

 

debug에서는 문제가 없었으나, release를 하는 과정에서만  오류를 발생시켜 애를 태우더군요. ㅠㅠ;;

 

Fatal Exception: com.google.firebase.FirebaseException: An internal error has occurred. [ Instantiation of JsonResponse failed! class com.google.android.gms.internal.firebase-auth-api.zzok ]
       at co m.google.firebase.auth.api.internal.zzem.zza(com.google.firebase:firebase-auth@@20.0.0:29) 
       at co m.google.firebase.auth.api.internal.zzfx.zza(com.google.firebase:firebase-auth@@20.0.0:14) 
       at co m.google.firebase.auth.api.internal.zzfs.zza(com.google.firebase:firebase-auth@@20.0.0:44) 
       at co m.google.firebase.auth.api.internal.zzel.zza(com.google.firebase:firebase-auth@@20.0.0:10) 
       at co m.google.firebase.auth.api.internal.zzac.zza(com.google.firebase:firebase-auth@@20.0.0:2) 
       at co m.google.android.gms.common.util.DeviceProperties.zza(com.google.android.gms:play-services-basement@@17.1.1:131) 
       at co m.google.firebase.auth.api.internal.zzfn.zza(com.google.firebase:firebase-auth@@20.0.0:10) 
       at co m.google.firebase.auth.api.internal.zzep.zza(com.google.firebase:firebase-auth@@20.0.0:53)

 

Instantiation of JsonResponse failed!  ...

말 그대로 응답으로 받는 JSON 결과를 분석할 수 없다는 에러를 발생 시킵니다.

 

먼저 gradle의 내용 중에 특별한 것을 보겠습니다. 

 

buildTypes {
    debug {
        resValue("string", "ADMOB_APP_ID", localProperties.getProperty("ADMOB_APP_ID"))
        resValue("string", "ADMOB_BANNER_ID", localProperties.getProperty("ADMOB_BANNER_ID"))
    }
    release {
        resValue("string", "ADMOB_APP_ID", localProperties.getProperty("ADMOB_APP_ID"))
        resValue("string", "ADMOB_BANNER_ID", localProperties.getProperty("ADMOB_BANNER_ID"))
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

debug 시에는 사용하지 않으나, release을 할 때 사용하게 되는 2가지가 있습니다. 코드 난독화와 압축을 이한 선택 사항입니다.  playstore에 게시를 하고자 할 때 선택 해야 하는 요소들 중에 하나입니다.  

 

이유는 앱의 크기를 조금이라도 줄여야 한다는 구글의 압박(?)이 있고,  난독화를 통해 앱을 디버깅하려는 분에게 피곤함(?)을 남겨 두기 위해서입니다. 

 

그래도 proguard 설정을 통해서 난독화 등에서 제외시킬 수 있도록 하고 있기 때문에 꼭 필요한 부분은 제외 등록을 해서 처리를 하고 있기는 합니다. 

 

아무튼 이번에 하고자 하는 이야기의 주된 목적은 압축을 해서 앱 크기를 줄이는 처리를 진행하는 동안에 release 된 앱이 오류를 발생시킨다는 것입니다.  Instantiation of JsonResponse failed!...

 

https://github.com/firebase/firebase-android-sdk/issues/2124

 

Firebase Auth crash when R8 full mode obfuscation enabled · Issue #2124 · firebase/firebase-android-sdk

[READ] Step 1: Are you in the right place? Y [REQUIRED] Step 2: Describe your environment Android Studio version: 4.0 Firebase Component: Auth Component version: 20.0.0 [REQUIRED] Step 3: Describe ...

github.com

이미 많은 개발자들이 같은 증상에 대한 고민을 하고 있었더군요.  아무튼 그 덕분에  며칠을 허비하기는 했으나, 그 결론을 오늘에서야 내릴 수 있게 되었습니다. 

 

조치 방안

먼저 progurad-rules.pro 파일에 아래와 같이 추가해 주었습니다. 

 


-keep public class com.google.firebase.** {*;}
-keep class com.google.android.gms.internal.** {*;}
-keepclasseswithmembers class com.google.firebase.FirebaseException

다음은 gradle.properties 파일에 추가해 주었습니다. 

# firebase auth minifyEnabled = true 설정시 인증 오류 JSON 파싱 안되요...
android.enableR8.fullMode=true

 

그리고 project의 gradle 파일의 설정은 다음과 같이 수정해 주었습니다. 

buildscript {
    ext {
        compose_version = '1.4.3'
        raamcosta_version = '1.8.41-beta'
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.android.tools.build:gradle:8.0.1'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.5'
    }
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '8.0.1' apply false
    id 'com.android.library' version '8.0.1' apply false
    id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
}

gradle 버전이 8.0.1 이 현재 수준에서는 최신인 듯합니다. 그걸 사용하기 위해서  어느 날 문득 나타난 오류(?)와의 대면에서 며칠을 보냈습니다. ㅠㅠ;;

 

아무튼 이제 그 오류에서 해소되어 이렇게 정리된 글을 적어 두고자 합니다.  아닌가? ㅋ~

 

앱의 이메일 을 이용한 인증 화면

 

오늘도 즐~ 코딩 하세요.

반응형