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
0 comments No comments
{count} votes

1 answer

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.


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.