xamarin / GooglePlayServicesComponents

Other
315 stars 148 forks source link

Implementing this in .Net Maui 8 throws error on build when trying to implement Casting. #835

Closed Jricklefs closed 5 months ago

Jricklefs commented 8 months ago

Xamarin.Android Version (eg: 6.0):

.Net Maui 8

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

Android

Google Play Services Version

Xamarin.GooglePlayServices.Cast.Framework 121.3.0

Describe your Issue

Attempting to implement casting in android does not work. Throws build error.
It will build and deploy when deploying to windows machine but deploying to android cause the error.

The line of code in the example, is showing deprecated, but used to keep the code base minimal. If I use the new method, it causes the same error to be thrown. The only way I can get around the build error is to Roll back the version to 121.2.0.

Relevant information

Add relevant project settings from *.csproj file:

Packages used:

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

Build settings (tools)

    Visual Studio 22

or even better - links to the existing code:

NOTE: Please DO NOT submit screenshot images. Images are not searchable!

Minimal Repro Code Sample

If you want to speed up investigation and bug fixing: please provide minimal repro sample for tests.

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

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

Exception :

Severity    Code    Description Project File    Line    Suppression State
Error   JAVA0000    Error in C:\Users\josep\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.2\buildTransitive\net7.0-android33.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.class:
Type androidx.collection.LongSparseArrayKt$keyIterator$1 is defined multiple times: C:\Users\josep\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.2\buildTransitive\net7.0-android33.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.class, C:\Users\josep\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-ktx.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.class
Compilation failed
java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: C:\Users\josep\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.2\buildTransitive\net7.0-android33.0\..\..\jar\androidx.collection.collection-jvm.jar
androidx/collection/LongSparseArrayKt$keyIterator$1.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: C:\Users\josep\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.2\buildTransitive\net7.0-android33.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.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.LongSparseArrayKt$keyIterator$1 is defined multiple times: C:\Users\josep\.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.2\buildTransitive\net7.0-android33.0\..\..\jar\androidx.collection.collection-jvm.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.class, C:\Users\josep\.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0\..\..\jar\androidx.collection.collection-ktx.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.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:2056)
    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
    GPSDontWorkforCasting       1   
jonpryor commented 7 months ago

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

Applying the following patch to https://github.com/Jricklefs/GPSDontWorkforCasting will allow it to build:

diff --git a/GPSDontWorkforCasting/GPSDontWorkforCasting.csproj b/GPSDontWorkforCasting/GPSDontWorkforCasting.csproj
index 6b39405..279d57b 100644
--- a/GPSDontWorkforCasting/GPSDontWorkforCasting.csproj
+++ b/GPSDontWorkforCasting/GPSDontWorkforCasting.csproj
@@ -66,6 +66,8 @@
      <PackageReference Include="Xamarin.GooglePlayServices.Cast.Framework">
        <Version>121.3.0.5</Version>
      </PackageReference>
+     <PackageReference Include="Xamarin.AndroidX.Collection.Jvm" Version="1.4.0" />
+     <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.0" />
    </ItemGroup>

 </Project>

Consider your error message:

Type androidx.collection.LongSparseArrayKt$keyIterator$1 is defined multiple times: C:\Users\josep.nuget\packages\xamarin.androidx.collection.jvm\1.3.0.2\buildTransitive\net7.0-android33.0....\jar\androidx.collection.collection-jvm.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.class, C:\Users\josep.nuget\packages\xamarin.androidx.collection.ktx\1.2.0.9\buildTransitive\net6.0-android31.0....\jar\androidx.collection.collection-ktx.jar:androidx/collection/LongSparseArrayKt$keyIterator$1.class

Within those paths are the package names causing the conflict, after packages\:

Search for those packages on , and add a @(PackageReference) to use the latest version of those packages. This is what the above patch does, explicitly referencing Xamarin.AndroidX.Collection.Jvm 1.4.0 and Xamarin.AndroidX.Collection.Ktx 1.4.0. This allows the project to build.

moljac commented 7 months ago

Added PR to the repro sample.

It was a bit more than JonP suggested.

    <ItemGroup Condition="( '$(TargetFramework)' == 'net8.0-android' )">
        <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.0" />
        <PackageReference Include="Xamarin.AndroidX.Collection.Jvm" Version="1.4.0" />
        <PackageReference Include="Xamarin.AndroidX.Preference" Version="1.2.1.3" />        
    </ItemGroup>
moljac commented 5 months ago

closing this issue