Gradle Gotcha When Adding Push Notifications to an Android App with FCM

Recently when installing push notifications using FCM to an existing Android Application I ran into dependency hell trying to get Firebase’s firebase-messaging library integrated. After hours of reading through vague stack-traces and troubleshooting it ended up being an incredibly easy problem to fix.

The Problem

Error:Error converting bytecode to dex:
Cause: com.android.dex.DexException: Multiple dex files define Lcom/google/android/gms/common/api/zza;

The problem comes from needing to utilize the play-services libraries while also needing to use the firebase libraries. The one being used in this project in particular was the play-services-cast for Chromecast (though it was included through other Gradle dependencies and not explicitly). When trying to install com.google.firebase:firebase-messaging:10.0.1 there was a version mismatch causing the app to crash during compile time.

The Solution

Upon inspecting the contents of the project’s External Libraries I noticed that there were quite a few play-services libraries that were on version 9.0.0. By explicitly including those libraries in the app-level Gradle file using version 10.0.1 the error went away and the app launched successfully.

Hopefully this is able to save you some time if you run into the same error!

Need help with a project? We'd love to hop on board. Hire Us.

Get In
Touch

Must be a valid email address.