firebase-unity-sdk: [Bug] Duplicate class com.google.firebase.ktx.Firebase found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime

[REQUIRED] Please fill in the following fields:

  • Unity editor version: 2020.3.48f
  • Firebase Unity SDK version: 11.5.0
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: _____ (Auth, Database, etc.)
  • Other Firebase Components in use: Analytics, Auth, Crashlytics, DynamicLinks, Messaging, RemoteCOnfig
  • Additional SDKs you are using: ApplovinMax, AppsFlyer
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: iOS, Android, desktop
  • Scripting Runtime: IL2CPP
  • Pre-built SDK from the website or open-source from this repo: repo

[REQUIRED] Please describe the issue here:

Can’t build android. Have following error: Execution failed for task ‘:launcher:checkReleaseDuplicateClasses’.

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? This could be a description, log/console output, etc.

A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable Duplicate class com.google.firebase.ktx.Firebase found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:) Duplicate class com.google.firebase.ktx.FirebaseCommonKtxRegistrar found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:) Duplicate class com.google.firebase.ktx.FirebaseCommonKtxRegistrar$getComponents$$inlined$coroutineDispatcher$1 found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:) Duplicate class com.google.firebase.ktx.FirebaseCommonKtxRegistrar$getComponents$$inlined$coroutineDispatcher$2 found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:) Duplicate class com.google.firebase.ktx.FirebaseCommonKtxRegistrar$getComponents$$inlined$coroutineDispatcher$3 found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:) Duplicate class com.google.firebase.ktx.FirebaseCommonKtxRegistrar$getComponents$$inlined$coroutineDispatcher$4 found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:) Duplicate class com.google.firebase.ktx.FirebaseKt found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:) Duplicate class com.google.firebase.ktx.FirebaseKt$coroutineDispatcher$1 found in modules jetified-com.google.firebase.firebase-common-20.4.0-runtime (:com.google.firebase.firebase-common-20.4.😇 and jetified-com.google.firebase.firebase-common-ktx-20.3.3-runtime (:com.google.firebase.firebase-common-ktx-20.3.3:)

If you have a downloadable sample project that reproduces the bug you’re reporting, you will likely receive a faster response on your issue.

Relevant Code:

// TODO(you): code here to reproduce the problem

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 21 (2 by maintainers)

Most upvoted comments

Android workaround

  • So, I found a way to fix this problem in local builds and CI builds:
  • Create any “Editor” folder in Assets
  • Create C# script and copy code from below
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class AndAnotherOneFixForFirebase : IPostprocessBuildWithReport, IPreprocessBuildWithReport
{
    public int callbackOrder => 0;

    public void OnPostprocessBuild(BuildReport report)
    {
        if (report.summary.platform != BuildTarget.Android)
            return;

        DeleteSpecificAar();
    }

    private static void DeleteSpecificAar()
    {
        string pathToAar = "Assets/Plugins/Android/com.google.firebase.firebase-common-ktx-20.3.3.aar";

        if (File.Exists(pathToAar))
        {
            File.Delete(pathToAar);
            AssetDatabase.Refresh();
            UnityEngine.Debug.Log("Specific .aar file deleted successfully.");
        }
        else
        {
            UnityEngine.Debug.LogWarning("Specified .aar file not found.");
        }
    }

    public void OnPreprocessBuild(BuildReport report)
    {
        WaitForBuildStart(report);
    }

    private static async void WaitForBuildStart(BuildReport report)
    {
        if (report.summary.platform != BuildTarget.Android)
            return;

        string pathToAar = "Assets/Plugins/Android/com.google.firebase.firebase-common-ktx-20.3.3.aar";

        await WaitForFile(pathToAar);
        
        if (File.Exists(pathToAar))
        {
            File.Delete(pathToAar);
            AssetDatabase.Refresh();
            UnityEngine.Debug.Log($"{pathToAar} deleted.");
        }
        else
        {
            UnityEngine.Debug.LogWarning($"{pathToAar} not found.");
        }
    }

    private static Task WaitForFile(string path)
    {
        return Task.Run(() =>
        {
            while (!File.Exists(path))
            {
                Task.Delay(500).Wait();
            }
        });
    }
}

It seems the bug in download_artifacts.gradle. I have a project and among transitive dependencies for different libraries there are versions: firebase-common:20.1.0, 20.2.0, 20.3.3 in project. and download_artifacts.gradle finally resolves them all as "firebase-common:+ " and it means it got last 20.4.0 version, that has conflict with firebase-common-ktx-20.3.3.

if I change resolution strategy to patching mainTemplate.gradle then all works fine and gradle resolves different dependencies (20.1.0, 20.2.0, 20.3.3) as 20.3.3 as expected, because it’s highest version for this package through all libraries.