firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
828 stars 428 forks source link

[Bug] Duplicate class com.google.firebase.iid.FirebaseInstanceIdReceiver found #1274

Closed revolt3r closed 2 years ago

revolt3r commented 2 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What's the issue repro rate? 100%

What happened? How can we make the problem occur? Building fails with the following error:

Execution failed for task ':launcher:checkDebugDuplicateClasses'.

1 exception was raised by workers: java.lang.RuntimeException: Duplicate class com.google.firebase.iid.FirebaseInstanceIdReceiver found in modules jetified-firebase-iid-20.0.1-runtime.jar (com.google.firebase:firebase-iid:20.0.1) and jetified-firebase-messaging-23.0.3-runtime.jar (com.google.firebase:firebase-messaging:23.0.3)

paulinon commented 2 years ago

Hi @revolt3r,

Thanks for reporting this issue. Could you try these steps and see if they help resolve the issue:

  1. Enable Custom Gradle Properties Template under Player Settings > Settings for Android > Publishing Settings
  2. Make sure these lines of code are present in your gradleTemplate.properties file:
    android.useAndroidX = true
    android.enableJetifier = true
  3. Select Force Resolve under Assets > External Dependency Manager > Android Resolver

I'm looking forward to your results.

revolt3r commented 2 years ago

Hi @paulinon,

These settings were all already in place. "Force Resolve" was successful, but I'm still getting the same "duplicate class" error during the build.

I forgot to mention that I'm upgrading from 8.6.2 to 8.10.1 -> I had no issues before the update.

mrtrizer commented 2 years ago

Same problem here. Firebase version: 8.10.1 upgrading from 8.7 Unity 2019.4.35f1 Gradle template already contains useAndroidX and enableJetifier set true

* What went wrong:
Execution failed for task ':launcher:checkReleaseDuplicateClasses'.
> 1 exception was raised by workers:
  java.lang.RuntimeException: Duplicate class com.google.firebase.iid.FirebaseInstanceIdReceiver found in modules jetified-firebase-iid-20.0.1-runtime.jar (com.google.firebase:firebase-iid:20.0.1) and jetified-firebase-messaging-23.0.3-runtime.jar (com.google.firebase:firebase-messaging:23.0.3)
paulinon commented 2 years ago

Thanks for the additional details, folks. I haven't encountered the error message yet. Could you provide the complete steps you've taken in replicating this issue?

revolt3r commented 2 years ago

There are no specific steps, it's just failing during a normal build. With Firebase 8.6.2 the build finished with no issues. After updating all Firebase libs to 8.10.1, the build started failing with this error.

It seems like the Messaging module is conflicting with the core Firebase (at least that's what it looks like from the error) @paulinon did you try to make a build with this mix of modules and it succeeds with no issues?

mrtrizer commented 2 years ago

I'm updating Firebase for the first time. This is how I did this:

  1. Downloaded Firebase 8.10.1 archive
  2. Deleted Firebase directory from Assets
  3. Imported new packages one by one (Auth, Messaging, Functions, Firestore, Functions, Database, Analytics, Storage)
  4. Restored google-services and GoogleService-Info in Firebase dir
  5. Made Force Reload in External Dependency Manager
  6. Tried to build as usually via BuildPipeline.BuildPlayer function

I also tried Library and obj dirs removal, didn't helped.

Gradle template:

unityStreamingAssets=.unity3d**STREAMING_ASSETS**
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
org.gradle.parallel=true
# Android Resolver Properties Start
android.useAndroidX=true
android.enableJetifier=true
# Android Resolver Properties End
**ADDITIONAL_PROPERTIES**

If you need content of other files, just let me know.

It looks like the deprecated library jetified-firebase-iid is taken from maven. I'm not sure is it really needed for the project or not, but I just can't find out why it's downloaded and what package requires it because it's not present in any of my Dependencies.xml files. Maybe I need to update some other package in addition to Firebase or something like this.

paulinon commented 2 years ago

Thanks for the additional context, folks. I was able to replicate this issue when multiple Firebase products are in the Unity project as you described. I'll relay my findings to the team.

That being said, I'll be marking this as a bug for now. You may refer to this thread for any updates.

mrtrizer commented 2 years ago

Btw looks like the same or at least related problem https://github.com/firebase/quickstart-unity/issues/1093

The line <androidPackage spec="com.google.firebase:firebase-iid:21.1.0"> </androidPackage> has disapeared from MessagingDependencies.xml according to diff.

Build worked for me after adding this dependency to Messaging and running Resolve

a-maurice commented 2 years ago

Thanks for flagging this, it seems the extra dependency got lost when we transitioned to the new build system. The workaround is as @mrtrizer pointed out above, adding <androidPackage spec="com.google.firebase:firebase-iid:21.1.0"> </androidPackage> to the MessagingDependencies.xml file manually.

a-maurice commented 2 years ago

We've released a new version of the Firebase for Unity SDK, 9.0.0, available here: https://github.com/firebase/firebase-unity-sdk/releases/tag/v9.0.0, that includes the fix for this. Thanks again for flagging it.