xamarin / GooglePlayServicesComponents

Other
315 stars 146 forks source link

Adding xamarin.googleplayservices.auth to .Net Maui app causes compile errors #909

Closed dmanning23 closed 1 month ago

dmanning23 commented 2 months ago

Xamarin.Android Version (eg: 6.0):

.net8.0-android

Operating System & Version (eg: Mac OSX 10.11):

Win11

Google Play Services Version

xamarin.googleplayservices.auth 121.2.0.2

Describe your Issue

Adding the xamarin.googleplayservices.auth package to a .Net Maui app causes compilation errors (see "build logs" section)

Relevant information

Add relevant project settings from *.csproj file:

Packages used:

    <ItemGroup>
        <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.90" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.90" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
    </ItemGroup>

    <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
      <PackageReference Include="Xamarin.GooglePlayServices.Auth">
        <Version>121.2.0.2</Version>
      </PackageReference>
    </ItemGroup>

Minimal Repro Code Sample

https://github.com/dmanning23/GooglePlayServicesBug

Steps to Reproduce (with link to sample solution if possible):

Create a new .Net Maui app Add the xamarin.googleplayservices.auth nuget package The app no longer compiles

Include any relevant Exception Stack traces, build logs, adb logs:

Build started at 7:42 PM...
1>------ Build started: Project: MauiApp1, Configuration: Debug Any CPU ------
1>MauiApp1 -> C:\Projects\MauiApp1\MauiApp1\bin\Debug\net8.0-ios\iossimulator-arm64\MauiApp1.dll
1>MauiApp1 -> C:\Projects\MauiApp1\MauiApp1\bin\Debug\net8.0-maccatalyst\maccatalyst-arm64\MauiApp1.dll
1>MauiApp1 -> C:\Projects\MauiApp1\MauiApp1\bin\Debug\net8.0-android\MauiApp1.dll
1>MauiApp1 -> C:\Projects\MauiApp1\MauiApp1\bin\Debug\net8.0-windows10.0.19041.0\win10-arm64\MauiApp1.dll
1>MSBUILD : java.exe error JAVA0000: Error in C:\Users\danmanning\.nuget\packages\xamarin.androidx.collection.jvm\1.4.3.1\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class:
1>MSBUILD : java.exe error JAVA0000: Type androidx.collection.ArrayMapKt is defined multiple times: C:\Users\danmanning\.nuget\packages\xamarin.androidx.collection.jvm\1.4.3.1\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, C:\Users\danmanning\.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
1>MSBUILD : java.exe error JAVA0000: Compilation failed
1>MSBUILD : java.exe error JAVA0000: java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\danmanning\.nuget\packages\xamarin.androidx.collection.jvm\1.4.3.1\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar
1>MSBUILD : java.exe error JAVA0000: androidx/collection/ArrayMapKt.class
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:135)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.main(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:5)
1>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\danmanning\.nuget\packages\xamarin.androidx.collection.jvm\1.4.3.1\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class
1>MSBUILD : java.exe error JAVA0000:    at Version.fakeStackEntry(Version_8.2.33.java:0)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.T.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:5)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:82)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:32)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:31)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.b(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:2)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:42)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.b(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:13)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:40)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:122)
1>MSBUILD : java.exe error JAVA0000:    ... 1 more
1>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.utils.b: Type androidx.collection.ArrayMapKt is defined multiple times: C:\Users\danmanning\.nuget\packages\xamarin.androidx.collection.jvm\1.4.3.1\buildTransitive\net8.0-android34.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/ArrayMapKt.class, C:\Users\danmanning\.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
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.Q2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:21)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.D2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:54)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.D2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:10)
1>MSBUILD : java.exe error JAVA0000:    at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.D2.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:6)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.graph.m4$a.d(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:6)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.dex.c.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:61)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.dex.c.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:12)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.dex.c.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:9)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:45)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.d(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:17)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.D8.c(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:69)
1>MSBUILD : java.exe error JAVA0000:    at com.android.tools.r8.utils.S0.a(R8_8.2.33_429c93fd24a535127db6f4e2628eb18f2f978e02f99f55740728d6b22bef16dd:28)
1>MSBUILD : java.exe error JAVA0000:    ... 6 more
1>MSBUILD : java.exe error JAVA0000:
1>Done building project "MauiApp1.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 7:42 PM and took 03.645 seconds ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
========== Deploy completed at 7:42 PM and took 03.645 seconds ==========
jpobst commented 2 months ago

https://github.com/xamarin/AndroidX/issues/764

dmanning23 commented 1 month ago

Thank you, the suggestions in the 764 ticket solved that issue. I've had another similar issue come up when I add the following packages though:

      <PackageReference Include="Xamarin.Google.Android.Play.Core">
        <Version>1.10.3.14</Version>
      </PackageReference>
      <PackageReference Include="Xamarin.Google.Android.Play.Core.Common">
        <Version>2.0.4.2</Version>
      </PackageReference>

I'm working on a project where these 2 packages are added as transitive packages. These are the latest versions from Nuget, they are both published on the same day but the version numbers don't line up at all.

I've updated the example project to demonstrate these errors. When it is compiled, the following XA4215 errors are thrown:

1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): warning XA4214: The managed type `Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListener` exists in multiple assemblies: Xamarin.Google.Android.Play.Core, Xamarin.Google.Android.Play.Core.Common. Please refactor the managed type names in these assemblies so that they are not identical.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): warning XA4214: References to the type `Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListener` will refer to `Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListener, Xamarin.Google.Android.Play.Core`.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): warning XA4214: The managed type `Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerImplementor` exists in multiple assemblies: Xamarin.Google.Android.Play.Core, Xamarin.Google.Android.Play.Core.Common. Please refactor the managed type names in these assemblies so that they are not identical.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): warning XA4214: References to the type `Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerImplementor` will refer to `Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerImplementor, Xamarin.Google.Android.Play.Core`.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): warning XA4214: The managed type `Xamarin.Google.Android.Play.Core.Common.IIntentSenderForResultStarter` exists in multiple assemblies: Xamarin.Google.Android.Play.Core, Xamarin.Google.Android.Play.Core.Common. Please refactor the managed type names in these assemblies so that they are not identical.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): warning XA4214: References to the type `Xamarin.Google.Android.Play.Core.Common.IIntentSenderForResultStarter` will refer to `Xamarin.Google.Android.Play.Core.Common.IIntentSenderForResultStarter, Xamarin.Google.Android.Play.Core`.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215: The Java type `com.google.android.play.core.listener.StateUpdatedListener` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215:   `com.google.android.play.core.listener.StateUpdatedListener` generated by: Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListener, Xamarin.Google.Android.Play.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215:   `com.google.android.play.core.listener.StateUpdatedListener` generated by: Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListener, Xamarin.Google.Android.Play.Core.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215: The Java type `mono.com.google.android.play.core.listener.StateUpdatedListenerImplementor` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215:   `mono.com.google.android.play.core.listener.StateUpdatedListenerImplementor` generated by: Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerImplementor, Xamarin.Google.Android.Play.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215:   `mono.com.google.android.play.core.listener.StateUpdatedListenerImplementor` generated by: Xamarin.Google.Android.Play.Core.Listener.IStateUpdatedListenerImplementor, Xamarin.Google.Android.Play.Core.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215: The Java type `com.google.android.play.core.common.IntentSenderForResultStarter` is generated by more than one managed type. Please change the [Register] attribute so that the same Java type is not emitted.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215:   `com.google.android.play.core.common.IntentSenderForResultStarter` generated by: Xamarin.Google.Android.Play.Core.Common.IIntentSenderForResultStarter, Xamarin.Google.Android.Play.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\tools\Xamarin.Android.Common.targets(1536,3): error XA4215:   `com.google.android.play.core.common.IntentSenderForResultStarter` generated by: Xamarin.Google.Android.Play.Core.Common.IIntentSenderForResultStarter, Xamarin.Google.Android.Play.Core.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
jpobst commented 1 month ago

Google deprecated Google.Android.Play.Core and split its code into separate packages like Google.Android.Play.Core.Common. Thus they contain the same code and cannot be used together. You will need to fully use one or the other.

https://developer.android.com/guide/playcore#playcore-migration