Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Jricklefs opened this issue Jan 30, 2024 · 3 comments

Comments

@Jricklefs
Copy link

Jricklefs commented Jan 30, 2024

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
Copy link
Member

See also: xamarin/AndroidX#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\:

  • xamarin.androidx.collection.jvm
  • xamarin.androidx.collection.ktx

Search for those packages on <nuget.org>, 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
Copy link
Member

moljac commented Feb 14, 2024

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
Copy link
Member

moljac commented Apr 30, 2024

closing this issue

@moljac moljac closed this as completed Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants