레이블이 FCM인 게시물을 표시합니다. 모든 게시물 표시
레이블이 FCM인 게시물을 표시합니다. 모든 게시물 표시

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


2018년 6월 5일 화요일

FCM(Firebase Cloud Messaging) 안드로이드 앱을 만드는 중에 is not assignable to 'android.app.Service' Validates resource references inside Android XML files 에러 해법





FCM 안드로이드 앱을 만드는 중에 아래와 같은 에러가 발생하는 원인과 해결책

가정하기를 
 -. 패키지명 : com.example.joe.exfcmtest
 -. com.google.firebase.messaging.FirebaseMessagingService를 상속받을 클래스가 MyFirebaseMessagingService라고 할때

이러한 상황가운데서 아래와 같은 에러를 만난다면 

'com.example.joe.exfcmtest.MyFirebaseMessagingService' is not assignable to 'android.app.Service' less... (Ctrl+F1) 
Validates resource references inside Android XML files.

앱 수준의 build.gradle(프로젝트 수준의 build.gradle이 아님)에서 필요한 아래의 dependencies가 빠져 있어서의 문제다.

compile 'com.google.firebase:firebase-messaging:12.0.1'  (버전은 현재의 최신 버전과 다를수 있음)

이 문제는 참으로 황당하게도 구글의 Firebase SDK 추가에 대한 설명 자체에서 빼먹고 제시해 주지 않음으로 인해 만나게되는 황당한 에러이다.
Firebase 콘솔에서 제시한 대로 따라하다보면 아래 이미지에서 보듯이 compile 'com.google.firebase:firebase-messaging:12.0.1'를 포함시키라는 설명이 전혀 없다. 나쁜...



이로인해 Manifest 파일의 com.google.firebase.messaging.FirebaseMessagingService를 상속받을 Service 클래스에 대해 아래 그림과 같은 에러가 발생한다.

        <service android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>



그리고 다음 에러



이 문제를 해결할려면 아래 그림에서 보는바와 같이 앱 수준의 build.gradle



compile 'com.google.firebase:firebase-messaging:12.0.1'를 dependencies에 포함시켜야 된다.



안드로이드는 너무 자주, 많이 바뀌는 통에...