the_smart_home_maker
the_smart_home_maker

Reputation: 524

React Native Android Duplicate class com.google.android.gms.gcm.PendingCallback found in modules jetified-firebase-jobdispatcher-0.6.0-runtime.jar

I am facing a problem with my React Native Android project. I am currently working on integrating AWS Amplify Push Notifications. I am receiving the following "Duplicate Classes" dependency error and I don't know, where it might originate from. Do you have a solution for this problem?

What I already did:

+--- project :aws-amplify_pushnotification
...
|    \--- com.firebase:firebase-jobdispatcher:0.6.0

Has anybody faced this problem already and knows a solution?

Thanks a lot in advance!

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class com.google.android.gms.gcm.PendingCallback found in modules jetified-firebase-jobdispatcher-0.6.0-runtime.jar (com.firebase:firebase-jobdispatcher:0.6.0) and jetified-play-services-gcm-16.1.0-runtime.jar (com.google.android.gms:play-services-gcm:16.1.0)
  Duplicate class com.google.android.gms.internal.measurement.zzu found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement:19.0.0)
  Duplicate class com.google.android.gms.internal.measurement.zzv found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement:19.0.0)
  Duplicate class com.google.android.gms.internal.measurement.zzw found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement:19.0.0)
  Duplicate class com.google.android.gms.measurement.AppMeasurement found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-impl-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement-impl:19.0.0)
  Duplicate class com.google.android.gms.measurement.AppMeasurement$ConditionalUserProperty found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-impl-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement-impl:19.0.0)
  Duplicate class com.google.android.gms.measurement.AppMeasurement$EventInterceptor found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-impl-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement-impl:19.0.0)
  Duplicate class com.google.android.gms.measurement.AppMeasurement$OnEventListener found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-impl-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement-impl:19.0.0)
  Duplicate class com.google.android.gms.measurement.AppMeasurementContentProvider found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-impl-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement-impl:19.0.0)
  Duplicate class com.google.android.gms.measurement.internal.zza found in modules jetified-firebase-analytics-impl-16.2.4-runtime.jar (com.google.firebase:firebase-analytics-impl:16.2.4) and jetified-play-services-measurement-impl-19.0.0-runtime.jar (com.google.android.gms:play-services-measurement-impl:19.0.0)
 ...

There is also a bug filed on GitHub about this issue but the bug has been closed with no actual resolution :( https://github.com/aws-amplify/amplify-js/issues/4593

Upvotes: 0

Views: 2190

Answers (2)

Tiberiu Popescu
Tiberiu Popescu

Reputation: 4524

It may happen if you have 2 different versions from the same package, for example this will cause the error:

implementation 'com.google.android.gms:play-services-analytics:17.0.0'
implementation 'com.google.android.gms:play-services-tagmanager:17.0.1'

To solve it, just make it the same version for both:

implementation 'com.google.android.gms:play-services-analytics:17.0.0'
implementation 'com.google.android.gms:play-services-tagmanager:17.0.0'

Upvotes: 1

the_smart_home_maker
the_smart_home_maker

Reputation: 524

Hi stackoverflow community,

after about a week of investigating and also opening a ticket in the aws-amplify-js github project, I was now able to solve the problem. In the following, I want to describe the solution if any of you might face the same problem in the future.

Here's the github ticket I had created on aws-amplify-js: https://github.com/aws-amplify/amplify-js/issues/8389

In my app/build.gradle I had the following definitions related to firebase and play-services:

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:28.0.1')

// Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-analytics'

implementation "com.google.android.gms:play-services-gcm:17.0.0"
...
configurations.all {
        resolutionStrategy {
            force 'com.google.android.gms:play-services-gcm:16.1.0'
            force 'com.google.android.gms:play-services-base:16.1.0'
            force 'com.google.firebase:firebase-core:16.0.6'
            force 'com.google.firebase:firebase-messaging:17.6.0'
        }
    }

I had taken those definitions from different resources explaining how to integrate aws amplify push notifications and analytics.

Replacing all of those definitions with just the following two lines did the trick and allowed me to build my Android app again without a duplicate classes error:

implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-messaging:15.0.2"

Best The Smart Home Maker

Upvotes: 0

Related Questions