Search code examples
androidpush-notificationfirebase-cloud-messagingandroid-push-notification

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > duplicate entry: com/google/android/gms/gcm/PendingCallback.class


The app compiles correctly in a device with Android 6.0, but not in a phone with Android 4.4.2. When I try to compile the project from Android Studio 2.2.3, using the device with Android 4.4.2, I receive this error:

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/gcm/PendingCallback.class

In my build.gradle file, I am using this:

dependencies {
    ......
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.google.firebase:firebase-messaging:9.0.0'
    ......
}

I already tried Build/Clean Project as suggested by SergioLucas at Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug', and I also tried using the same version in all of the Google Play Services libs, as suggested by Benjamin at Android studio APK buil error transformClassesWithJarMergingForDebug. In my case, using 9.8.0 for both com.google.android.gms:play-services and com.google.firebase:firebase-messaging did not fix the error. Any ideas? Thank you.

EDIT:

The app compiles correctly and zero problems on devices with Android 5.1.1, 5.0.1, and 6.0. I am experiencing this error only on my testing device with Android 4.4.2. See image error:

enter image description here

It intrigues me the fact that the error is only happening in Android 4.x, and everything compiles and works properly on devices with Android 5.x and 6.x. Maybe I need a specific library to make things compatible with older versions of Android, in this case Android 4.x? I will appreciate if you could provide any hints to fix this error. Thank you.


Solution

  • The solution was the code that sampyng shared at https://github.com/firebase/firebase-jobdispatcher-android/issues/3. This is what I had in my app/build.gradle file (version that was generating the error):

    dependencies {
        .........
        compile 'com.google.android.gms:play-services:9.8.0'
        compile 'com.google.firebase:firebase-messaging:9.0.0'
        .........
        compile 'com.firebase:firebase-jobdispatcher:0.6.0'
    }
    

    The solution was replacing compile 'com.firebase:firebase-jobdispatcher:0.6.0' with

    compile ("com.firebase:firebase-jobdispatcher-with-gcm-dep:0.6.0") {
        exclude module: "play-services-gcm"
    }
    

    The final version of the code that fixed the error was:

    dependencies {
        .........
        compile 'com.google.android.gms:play-services:9.8.0'
        compile 'com.google.firebase:firebase-messaging:9.0.0'
        .........
        compile ("com.firebase:firebase-jobdispatcher-with-gcm-dep:0.6.0") {
            exclude module: "play-services-gcm"
        }
    }
    

    I also found at https://medium.com/wiselteach/firebase-jobdispatcher-androidmonk-3e6d729ed9ce a related article that may be helpful to explain the use of the Firebase JobDispatcher, but the official documentation is at https://github.com/firebase/firebase-jobdispatcher-android.

    I tested on devices with Android 4.4.2, 5.0.1, 5.1.1 and 6.0. The app compiles correctly for me now.