在模块 jetified-firebase-jobdispatcher-0.6.0-runtime.jar 中发现 React Native Android 重复 class com.google.android.gms.gcm.PendingCallback

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

我的 React Native Android 项目遇到问题。我目前正在致力于集成 AWS Amplify Push Notifications。我收到以下“重复 类”依赖性错误,我不知道它可能源自何处。你有解决这个问题的方法吗?

我已经做了:

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

有没有人已经遇到过这个问题并且知道解决方案?

提前致谢!

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)
 ...

GitHub 上也有关于此问题的错误,但该错误已关闭,没有实际解决方案:( https://github.com/aws-amplify/amplify-js/issues/4593

嗨,Whosebug 社区,

经过大约一周的调查并在 aws-amplify-js github 项目中开了一张票,我现在能够解决问题了。下面,如果大家以后遇到同样的问题,我想描述一下解决方法。

这是我在 aws-amplify-js 上创建的 github 票证: https://github.com/aws-amplify/amplify-js/issues/8389

在我的 app/build.gradle 中,我有以下与 firebase 和播放服务相关的定义:

// 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'
        }
    }

我从不同的资源中获取了这些定义,解释了如何集成 aws amplify 推送通知和分析。

仅用以下两行替换所有这些定义就成功了,让我可以再次构建我的 Android 应用程序而不会出现重复的 类 错误:

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

最佳 智能家居制造商

如果您有来自同一个包的 2 个不同版本,则可能会发生这种情况,例如这会导致错误:

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

要解决这个问题,只需将两者设为相同的版本即可:

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