2018년 6월 6일 수요일

FCM 안드로이드 앱 개발시 error: cannot access zzbgl, class file for com.google.android.gms.internal.zzbgl not found 에러 해법





FCM 안드로이드 앱 개발시 error: cannot access zzbgl, class file for com.google.android.gms.internal.zzbgl not found 에러 해법

Firebase Cloud Messaging 안드로이드 개발시 아래와 같은 에러를 만나는 경우가 있다.
이 에러는 라이브러리로 인한 에러인데 FCM에서 library로 인한 에러의 경우 컴파일 단계에서 원천적으로 되지 않는 경우가 발생한다.
남의 라이브러리를 사용할때마다 늘상 씨름을 한판하지 않고는 쉽게 넘어가지를 않는 것 같다.
com.google.firebase.messaging.FirebaseMessagingService를 상속받은 MyFirebaseMessagingService 클래스에서 아래와 같은 에러가 발생하면서 컴파일이 되지를 않는다.

D:\ExFCMTest\app\src\main\java\com\example\joe\exfcmtest\MyFirebaseMessagingService.java:29: error: cannot access zzbgl
        Map<String, String> data = remoteMessage.getData();
                                                ^
  class file for com.google.android.gms.internal.zzbgl not found
Note: D:\ExFCMTest\app\src\main\java\com\example\joe\exfcmtest\MyFirebaseMessagingService.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
:app:compileDebugJavaWithJavac FAILED
:app:buildInfoGeneratorDebug

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
18 actionable tasks: 7 executed, 11 up-to-date


이 에러가 발생했을 때의 앱 수준의 build.gradle(app/build.gradle)에 있는 dependencies의 내용이다.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.google.firebase:firebase-core:16.0.0'
    compile 'com.google.firebase:firebase-messaging:12.0.1'
}

이 문제는 앱 수준의 build.gradle의 dependencies의  

compile 'com.google.firebase:firebase-core:16.0.0'를 

compile 'com.google.firebase:firebase-core:11.8.0' 

로 바꾸었더니 정상적으로 compile이 되었다. 그래서 dependencies가 아래와 같은 모양을 이루었다.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:12.0.1'
}

이제 컴파일이 되어 Firebase Console 창에서 푸시 메시지를 해당 앱으로 날리니 이번에는 앱이 강제 종료가 된다. 아래와 같은 에러 메시지를 뿜으면서

06-06 18:40:14.223 13813-16293/com.example.joe.exfcmtest E/AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
    Process: com.example.joe.exfcmtest, PID: 13813
    java.lang.NoSuchMethodError: No static method zzamg()Lcom/google/android/gms/common/util/zzd; in class Lcom/google/android/gms/common/util/zzh; or its super classes (declaration of 'com.google.android.gms.common.util.zzh' appears in /data/app/com.example.joe.exfcmtest-1/split_lib_dependencies_apk.apk)
        at com.google.android.gms.internal.zzcim.<init>(Unknown Source)
        at com.google.android.gms.internal.zzcim.zzdx(Unknown Source)
        at com.google.android.gms.measurement.AppMeasurement.getInstance(Unknown Source)
        at com.google.firebase.messaging.zzd.zzde(Unknown Source)
        at com.google.firebase.messaging.zzd.zzc(Unknown Source)
        at com.google.firebase.messaging.zzd.zzf(Unknown Source)
        at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(Unknown Source)
        at com.google.firebase.iid.zzc.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
        at java.lang.Thread.run(Thread.java:762)
06-06 18:40:14.287 13813-13813/com.example.joe.exfcmtest D/ViewRootImpl@c3f2698[MainActivity]: mHardwareRenderer.destroy()#4
    dispatchDetachedFromWindow
06-06 18:40:14.360 13813-13813/com.example.joe.exfcmtest D/InputTransport: Input channel destroyed: fd=70

이 문제는 라이브러리들의 버전이 일치하지 않아서 발생하는 문제이다. 위의 dependencies를 보면 아래와 같이 11.8.0과 12.0.1이 혼재되어 있다.

    compile 'com.google.firebase:firebase-core:11.8.0'
    compile 'com.google.firebase:firebase-messaging:12.0.1'

따라서     

compile 'com.google.firebase:firebase-messaging:12.0.1'를     

compile 'com.google.firebase:firebase-messaging:11.8.0'

으로 바꾸었다.
바꾸는건 12.0.1을 11.8.0으로 바꾸어서 타이핑해 주면 된다.

그래서 dependencies가 아래와 같이 되었다.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//    compile 'com.google.firebase:firebase-core:16.0.0' //error: cannot access zzbfm
    compile 'com.google.firebase:firebase-core:11.8.0' //O.K.
    compile 'com.google.firebase:firebase-messaging:11.8.0'
}

이제 컴파일도 정상적으로 되고 Firebase Console창에서 푸시 메시지를 날리면 정상적으로 잘 수신을 한다.
참고로 루트 수준의 build.gradle에 다음과 같이 구글의 maven 저장소를 추가해 준다.

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com" //구글의 Maven repository
        }
    }
}

아래 사이트가 도움이 된다.

https://firebase.google.com/docs/android/setup?authuser=0#manually_add_firebase


댓글 없음:

댓글 쓰기