AndroidX icon indicating copy to clipboard operation
AndroidX copied to clipboard

Type androidx.savedstate.ViewKt is defined multiple times

Open williambuchanan2 opened this issue 6 months ago • 15 comments

Android framework version

net9.0-android

Affected platform version

Android 36

Description

I have upgraded my Maui app to Android 36 - everything ok.

I then went to update nuget packages and I get the below error at the end of the build.

11>MSBUILD : java.exe error JAVA0000: Error in obj\Debug\net9.0-android\lp\190\jl\classes.jar:androidx/savedstate/ViewKt.class: 11>MSBUILD : java.exe error JAVA0000: Type androidx.savedstate.ViewKt is defined multiple times: obj\Debug\net9.0-android\lp\190\jl\classes.jar:androidx/savedstate/ViewKt.class, obj\Debug\net9.0-android\lp\238\jl\classes.jar:androidx/savedstate/ViewKt.class 11>MSBUILD : java.exe error JAVA0000: Compilation failed 11>MSBUILD : java.exe error JAVA0000: java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net9.0-android\lp\190\jl\classes.jar 11>MSBUILD : java.exe error JAVA0000: androidx/savedstate/ViewKt.class 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.yu.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:131) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.main(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:5) 11>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, origin: obj\Debug\net9.0-android\lp\190\jl\classes.jar:androidx/savedstate/ViewKt.class 11>MSBUILD : java.exe error JAVA0000: at Version.fakeStackEntry(Version_8.7.18.java:0) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.T.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:5) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.yu.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:82) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.yu.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:32) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.yu.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:31) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.yu.b(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:2) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:42) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.b(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:13) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:40) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.yu.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:118) 11>MSBUILD : java.exe error JAVA0000: ... 1 more 11>MSBUILD : java.exe error JAVA0000: Caused by: com.android.tools.r8.internal.g: Type androidx.savedstate.ViewKt is defined multiple times: obj\Debug\net9.0-android\lp\190\jl\classes.jar:androidx/savedstate/ViewKt.class, obj\Debug\net9.0-android\lp\238\jl\classes.jar:androidx/savedstate/ViewKt.class 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.bd0.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:21) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.Z50.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:54) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.Z50.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:10) 11>MSBUILD : java.exe error JAVA0000: at java.base/java.util.concurrent.ConcurrentHashMap.merge(ConcurrentHashMap.java:2056) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.Z50.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:6) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.graph.s4$a.d(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:6) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.dex.c.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:95) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.dex.c.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:44) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.dex.c.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:9) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:45) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.d(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:17) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.D8.c(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:71) 11>MSBUILD : java.exe error JAVA0000: at com.android.tools.r8.internal.yu.a(R8_8.7.18_f8bee6d6fb926b7ebb3b15bf98f726f9d57471456ea20fce6d17d9a020197688:28) 11>MSBUILD : java.exe error JAVA0000: ... 6 more 11>MSBUILD : java.exe error JAVA0000: Directory 'obj\Debug\net9.0-android\lp\190' is from 'androidx.savedstate.savedstate-android.aar'. 11>MSBUILD : java.exe error JAVA0000: Directory 'obj\Debug\net9.0-android\lp\238' is from 'androidx.savedstate.savedstate-ktx.aar'.

Steps to Reproduce

Update Maui app to Android 36 Run nuget update

Did you find any workaround?

No

Relevant log output


williambuchanan2 avatar Aug 13 '25 01:08 williambuchanan2

same here,

Did you found some solution?

OMendozaG avatar Aug 17 '25 00:08 OMendozaG

same here,

Did you found some solution?

No solution yet - I think we need to wait for a proper fix.

williambuchanan2 avatar Aug 17 '25 22:08 williambuchanan2

Same story. Upgrading Xamarin.AndroidX.Credentials from 1.5.0.1 to 1.5.0.3 causes builds to fails with this error.

I'm using Microsoft.Maui.Controls 9.0.100 and CommunityToolkit.Maui 11.2.0.

wasker avatar Aug 18 '25 05:08 wasker

This is a pinned issue at the top of the issues page:

  • https://github.com/dotnet/android-libraries/issues/764

What happens is:

  • Google moved types from one library to another
  • We just mirror what they list for each package's dependencies. Most of the time they just list a range of versions, even though they moved a type...
  • You updated one package, but not the other.

Does this problem go away if you update all the packages, or look at the options in #764?

jonathanpeppers avatar Aug 18 '25 13:08 jonathanpeppers

Does this problem go away if you update all the packages, or look at the options in #764?

I managed to make some progress on this by painstakingly going through every transitive reference and including it in my Directory.Packages.props file which includes the latest version of all these packages - there are 80 of them so this was a lot of work.

This made the above error go away but I am still getting the below warnings - the strange thing about this being that it is listing the wrong versions in the warnings. For example, I have included Xamarin.AndroidX.Lifecycle.LiveData v 2.9.2.1 but the warning below says 2.8.7.3. Why is it trying to use that version when I haven't included it? Also, I don't want to have to list all the transitive packages - my understanding is that once you update it should automatically update these, but this doesn't seem to happen.

Is this at the root of the problem? I.e. the versioning is not working properly and therefore using a mix of old and new references? My point being, when I have specifically referenced 2.9.2.1, why is it still trying to use 2.8.7.3, and then giving me a warning about it? Should it not just use 2.9.2.1 and then update all transitive references to match that version?

warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.LiveData 2.8.7.3 requires Xamarin.AndroidX.Lifecycle.LiveData.Core (>= 2.8.7.3 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.LiveData.Core 2.9.2.1 was resolved.

warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.Runtime 2.8.7.3 requires Xamarin.AndroidX.Lifecycle.Common (>= 2.8.7.3 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.Common 2.9.2.1 was resolved.

warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.LiveData.Core.Ktx 2.8.7.3 requires Xamarin.AndroidX.Lifecycle.LiveData.Core (>= 2.8.7.3 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.LiveData.Core 2.9.2.1 was resolved.

warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.ViewModelSavedState 2.8.7.3 requires Xamarin.AndroidX.Lifecycle.LiveData.Core (>= 2.8.7.3 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.LiveData.Core 2.9.2.1 was resolved.

warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.Runtime.Android 2.8.7.3 requires Xamarin.AndroidX.Lifecycle.Common (>= 2.8.7.3 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.Common 2.9.2.1 was resolved.

warning NU1608: Detected package version outside of dependency constraint: Xamarin.AndroidX.Lifecycle.Common.Java8 2.8.7.2 requires Xamarin.AndroidX.Lifecycle.Common (>= 2.8.7.2 && < 2.8.8) but version Xamarin.AndroidX.Lifecycle.Common 2.9.2.1 was resolved.

williambuchanan2 avatar Aug 18 '25 21:08 williambuchanan2

Adding this reference fixed the issue for me:

<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.8.8.1" />

But a permanent FIX would be great! I got the same warnings as mentioned above, though i got them for month now!

RsZoli avatar Aug 22 '25 15:08 RsZoli

Is everyone here using MAUI? Is the actual problem you're updating packages newer than what MAUI depends on? Doing that will end up in a lot of transitive dependency pain.

It may only be fixed when MAUI bumps, such as this .NET 10 PR:

  • https://github.com/dotnet/maui/pull/31265

But then it will get worse again, if you update newer beyond what MAUI specifies.

jonathanpeppers avatar Aug 22 '25 15:08 jonathanpeppers

@jonathanpeppers I think we all are! he problem is the opposite, i updated the VS to 17.14.13, which updated MAUI!

"VS now includes MAUI 9.0.82 (SR8.2)" and this is what brought the problem! Referencing the packages individually makes the problem go away!

RsZoli avatar Aug 22 '25 18:08 RsZoli

Ideally MAUI would only update their underlying packages for major releases, like going from .NET 9 to 10.

It seems like them bumping the packages frequently is also an issue.

jonathanpeppers avatar Aug 22 '25 19:08 jonathanpeppers

@jonathanpeppers but if they bumped packages then why do we need to include more fresh versions?

it seems to me that they are far behind and that causes the problem

RsZoli avatar Aug 22 '25 19:08 RsZoli

why do we need to include more fresh versions?

Yes, it doesn't seem like you would always need the latest. Is this just something that dependabot is doing (or you see the package manager in VS shows updates)?

jonathanpeppers avatar Aug 22 '25 19:08 jonathanpeppers

Is everyone here using MAUI? Is the actual problem you're updating packages newer than what MAUI depends on? Doing that will end up in a lot of transitive dependency pain.

Yes using Maui. Not sure what you mean by "newer than what Maui depends on". I just go into nuget manager an click update. I'm not doing anything crazy.

It may only be fixed when MAUI bumps, such as this .NET 10 PR:

I think someone said the same thing just before going from .NET 8 to .NET 9 - but yet here we are still dealing with the problem...

williambuchanan2 avatar Aug 22 '25 22:08 williambuchanan2

Adding this reference fixed the issue for me:

<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.8.8.1" />

I had tried that, and a bunch of other recommendations but it didn't work. Possibly I have different dependencies.

williambuchanan2 avatar Aug 22 '25 22:08 williambuchanan2

In MAUI I used

<PackageReference Include="Xamarin.AndroidX.SavedState.SavedState.Ktx" Version="1.3.1.1" />

and it worked. NuGet did not update automatically from Version "1.2.1.16" to "1.3.1.1".

ElmarBeck avatar Aug 24 '25 16:08 ElmarBeck

Working on a fresh .net 9.0 solution, the package "Xamarin.AndroidX.SavedState.SavedState.Ktx" doesn't have support for net9.0, any workaround for that?

sttsalmelo avatar Sep 11 '25 11:09 sttsalmelo