firebase analytics integration issue in .net maui project for android

Ashish Gupta 0 Reputation points
2025-01-06T08:23:10.51+00:00
  • Xamarin.Firebase.Analytics - installed successfuly
  • Xamarin.Firebase.iOS.Analytics - installed successfully

i am trying to integrate firebase analytics in .net maui project but getting some unknown error on android.

Added google-services.json to android project & set build action as googleservicejson and addedGoogleService-Info.plist to iOS project.

working fine on iOS but facing some unknown error on android, please see the code below i have initiallized firebase -

public class MainActivity : MauiAppCompatActivity

  {
  

  public static Activity FormsContext { get; set; }

  protected override void OnCreate(Bundle savedInstanceState)

  {

      Window.SetStatusBarColor(Color.FromArgb("#FF73B650").ToPlatform());

      CrossFingerprint.SetCurrentActivityResolver(() => this);

      base.OnCreate(savedInstanceState);

      // Initialize Firebase

      FirebaseApp.InitializeApp(this);

  }
  }  

however am getting below error please help me to fix this:-

  /Users/ashishgupta/Projects/CCS_Mobile_Maui/CCS_MOBILE_MAUI/CCSMobile-MAUI/CCSMobile-MAUI: Error JAVA0000: Error in /Users/ashishgupta/.nuget/packages/xamarin.androidx.collection.jvm/1.4.5.1/buildTransitive/net8.0-android34.0/../../jar/androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class:
  
  Type androidx.collection.ArrayMapKt is defined multiple times: /Users/ashishgupta/.nuget/packages/xamarin.androidx.collection.jvm/1.4.5.1/buildTransitive/net8.0-android34.0/../../jar/androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, /Users/ashishgupta/.nuget/packages/xamarin.androidx.collection.ktx/1.2.0.9/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-ktx.jar:androidx/collection/ArrayMapKt.class
  
  Compilation failed
  
  java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/ashishgupta/.nuget/packages/xamarin.androidx.collection.jvm/1.4.5.1/buildTransitive/net8.0-android34.0/../../jar/androidx.collection.collection-jvm.jar
  
  androidx/collection/ArrayMapKt.class
  

at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:126)

at com.android.tools.r8.D8.main(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:5)
  Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: /Users/ashishgupta/.nuget/packages/xamarin.androidx.collection.jvm/1.4.5.1/buildTransitive/net8.0-android34.0/../../jar/androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class
  

at Version.fakeStackEntry(Version_8.1.56.java:0)

at com.android.tools.r8.M.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:5)

at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:81)

at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:32)

at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:31)

at com.android.tools.r8.utils.R0.b(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:2)

at com.android.tools.r8.D8.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:26)

at com.android.tools.r8.D8.b(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:13)

at com.android.tools.r8.D8.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:24)

at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:113)

... 1 more
  Caused by: com.android.tools.r8.utils.b: Type androidx.collection.ArrayMapKt is defined multiple times: /Users/ashishgupta/.nuget/packages/xamarin.androidx.collection.jvm/1.4.5.1/buildTransitive/net8.0-android34.0/../../jar/androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, /Users/ashishgupta/.nuget/packages/xamarin.androidx.collection.ktx/1.2.0.9/buildTransitive/net6.0-android31.0/../../jar/androidx.collection.collection-ktx.jar:androidx/collection/ArrayMapKt.class
  


at com.android.tools.r8.utils.O2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:21)

at com.android.tools.r8.utils.O2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:26)

at com.android.tools.r8.utils.A2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:44)

at com.android.tools.r8.utils.A2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:10)

at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2048)

at com.android.tools.r8.utils.A2.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:6)

at com.android.tools.r8.graph.b4$a.e(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:7)

at com.android.tools.r8.dex.c.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:58)

at com.android.tools.r8.dex.c.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:9)

at com.android.tools.r8.dex.c.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:8)

at com.android.tools.r8.D8.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:29)

at com.android.tools.r8.D8.d(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:17)

at com.android.tools.r8.D8.c(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:1)

at com.android.tools.r8.utils.R0.a(R8_8.1.56_756d1f50f618dd1c39c000f11defb367a21e9e866e3401b884be16c0950f6f79:28)

... 6 more
```   (JAVA0000) (CCSMobile-MAUI) java
Developer technologies | .NET | .NET MAUI
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2025-01-07T07:28:08.12+00:00

    Hello,

    Please install Xamarin.AndroidX.Fragment.Ktx nuget package.

    Here is my tested nuget package in MAUI demo, it is working as normal for android platform.

    <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
      <PackageReference Include="Xamarin.AndroidX.Fragment.Ktx">
          <Version>1.8.5.1</Version>
      </PackageReference>
      <PackageReference Include="Xamarin.Firebase.Analytics">
          <Version>122.1.2.1</Version>
      </PackageReference>
    </ItemGroup>
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Michael Le (WICLOUD CORPORATION) 1,295 Reputation points Microsoft External Staff
    2025-08-21T06:55:03.86+00:00

    Hello,

    The error is triggered by a version mismatch between Xamarin.AndroidX.Collection.Jvm (newer, net8-compatible) and Xamarin.AndroidX.Collection.Ktx (older, typically net6-era). These conflicting dependencies are included simultaneously, likely due to transitive dependencies or outdated package references.

    Recommendation

    • Remove or exclude Xamarin.AndroidX.Collection.Ktx from the Android target.
    • Ensure Xamarin.AndroidX.Collection.Jvm is included and align all AndroidX packages to net8-compatible versions.
    • Verify Firebase Analytics compatibility for Android and iOS.
    • Clean project caches and rebuild.

    Step-by-Step Plan:

    Step 1: Audit Android Dependency Graph

    • Execute the following command to inspect transitive dependencies for the Android target:
        dotnet list YourProject package --include-transitive --framework net8.0-android
      
    • Check for Xamarin.AndroidX.Collection.Ktx (e.g., version 1.2.0.9 or similar net6-era packages). If present, proceed to Step 2.

    Step 2: Update Project File to Resolve Dependency Conflict

    • Modify YourProject.csproj to exclude the conflicting Xamarin.AndroidX.Collection.Ktx package and ensure consistent, net8-compatible AndroidX and Firebase dependencies:
        <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
          <!-- Exclude conflicting KTX artifact -->
          <PackageReference Update="Xamarin.AndroidX.Collection.Ktx" ExcludeAssets="all" />
          <!-- Include JVM artifact for androidx.collection -->
          <PackageReference Include="Xamarin.AndroidX.Collection.Jvm" Version="1.4.5.1" />
          <!-- Align AndroidX dependencies to net8-compatible versions -->
          <PackageReference Include="Xamarin.AndroidX.Core" Version="1.13.1.3" />
          <PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.7.0.3" />
          <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.9.3.1" />
          <PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.8.5.1" />
          <!-- Firebase Analytics for Android -->
          <PackageReference Include="Xamarin.Firebase.Analytics" Version="122.1.2.1" />
          <!-- Include google-services.json -->
          <GoogleServicesJson Include="Platforms/Android/google-services.json" />
        </ItemGroup>
        <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
          <!-- Firebase Analytics for iOS -->
          <PackageReference Include="Xamarin.Firebase.iOS.Analytics" Version="10.28.0.1" />
        </ItemGroup>
      

    Step 3: Verify google-services.json Configuration

    • Ensure Platforms/Android/google-services.json is present and correctly configured.
    • Set its Build Action to GoogleServicesJson in the project file (as shown above).

    Step 4: Clean and Rebuild Project

    • Close your IDE.
    • Clear NuGet caches and project artifacts by running:
        dotnet nuget locals all --clear
      
    • Delete bin and obj directories in the project folder.
    • Restore and rebuild the project:
        dotnet restore
        dotnet build -c Debug
      

    Step 5: Validate Firebase Analytics Initialization

    • Confirm Firebase initialization in MainActivity.cs and test an analytics event:
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Initialize Firebase
            Firebase.FirebaseApp.InitializeApp(this);
            // Test Analytics
            var analytics = Firebase.Analytics.FirebaseAnalytics.GetInstance(Android.App.Application.Context);
            var bundle = new Android.OS.Bundle();
            bundle.PutString(Firebase.Analytics.Param.Method, "app_start");
            analytics.LogEvent(Firebase.Analytics.Event.Login, bundle);
        }
      

    Step 6: Ensure Consistent Target Framework

    • Verify that YourProject.csproj targets net8.0-android for Android builds and contains no references to net6.0-android or older AndroidX packages.
    • Ensure all AndroidX dependencies are aligned to a consistent version family to prevent similar conflicts.

    I hope this helps you resolve the issue.

    References

    You could use the following resources for further information:


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.