Version Conflict Detected for Xamarin.Android.Support

Both Xamarin.Forms and Xamarin.Essentials recently increased their Xamarin.Android.Support dependency to v28.0.0.3, and it might cause a weird error when updating NuGet Packages. Let's see how to fix it!

Version Conflict Detected for Xamarin.Android.Support

Both Xamarin.Forms and Xamarin.Essentials recently increased their Xamarin.Android.Support dependency to v28.0.0.3, and it might cause a weird error when updating NuGet Packages. Let's see how to fix it!

What's The Error?

When updating to the latest versions of Xamarin.Forms or Xamarin.Essentials, you may see one of these error messages:

Package restore failed. Rolling back package changes for 'MyApp.Android'.

or

Version conflict detected for Xamarin.Android.Support.Compat

(For nostalgia and SEO purposes, I've pasted the complete error message at the bottom of this blog post)

What Caused It?

Xamarin.Forms  v4.2.0.848062 and Xamarin.Essentials v1.3.1 now target v28.0.0.3 of the Xamarin.Android.Support libraries. But, their previous versions targeted v28.0.0.1 of the Xamarin.Android.Support libraries.

Xamarin.Forms v4.2.0.778463 Xamarin.Forms v4.2.0.848062
Xamarin.Forms v4.2.0.778463 Android Dependencies Xamarin.Forms v4.2.0.848062 Android Dependencies
Xamarin.Essentials v1.3.0 Xamarin.Essentials v1.3.1
Xamarin.Essentials v1.3.0 Android Dependencies Xamarin.Essentials v1.3.1 Android Dependencies

Updating Xamarin.Essentials before updating Xamarin.Forms in our Xamarin.Android project is causing a NuGet Package Dependency conflict where one package needs v28.0.0.3 while the other needs v28.0.0.1.

How Do We Fix It?

The quickest way to resolve this error is to update the NuGet Package references simultaneously, directly at the source.

In the Xamarin.Android project's csproj file, we can set the NuGet Version manually:

Before

<ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.2.0.709249" />
    <PackageReference Include="Xamarin.Essentials" Version="1.3.0" />
</ItemGroup>

After

<ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="4.2.0.848062" />
    <PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>

Note that I've removed every Xamarin.Android.Support library PackageReference

Conclusion

NuGet packages dependencies can sometimes be a pain, especially when two packages reference different versions of the same NuGet Package.

To fix this error in particular, we can update them both simultaneously in the Xamarin.Android csproj file.

Complete NuGet Error

  GET https://api.nuget.org/v3/registration3-gz-semver2/xamarin.essentials/index.json
  OK https://api.nuget.org/v3/registration3-gz-semver2/xamarin.essentials/index.json 270ms
Getting restore information for project /Users/bramin/Projects/MyApp/MyApp.Android/MyApp.Android.csproj
Getting restore information for project /Users/bramin/Projects/MyApp/MyApp.iOS/MyApp.iOS.csproj
Running non-parallel restore.
Reading project file /Users/bramin/Projects/MyApp/MyApp.Android/MyApp.Android.csproj.
Persisting no-op dg to /Users/bramin/Projects/MyApp/MyApp.Android/obj/MyApp.Android.csproj.nuget.dgspec.json
Restoring packages for /Users/bramin/Projects/MyApp/MyApp.Android/MyApp.Android.csproj...
Restoring packages for MonoAndroid,Version=v9.0...
Resolving conflicts for MonoAndroid,Version=v9.0...
Version conflict detected for Xamarin.Android.Support.Compat. Install/reference Xamarin.Android.Support.Compat 28.0.0.3 directly to project MyApp.Android to resolve this issue. 
 MyApp.Android -> Xamarin.Essentials 1.3.1 -> Xamarin.Android.Support.Compat (>= 28.0.0.3) 
 MyApp.Android -> Xamarin.Forms 4.2.0.709249 -> Xamarin.Android.Support.v4 28.0.0.1 -> Xamarin.Android.Support.Compat (= 28.0.0.1).
Checking compatibility of packages on MonoAndroid,Version=v9.0.
Checking compatibility for MyApp.Android 1.0.0 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Essentials 1.3.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Forms 4.2.0.709249 with MonoAndroid,Version=v9.0.
Checking compatibility for MyApp 1.0.0 with MonoAndroid,Version=v9.0.
Checking compatibility for System.Numerics.Vectors 4.5.0 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Compat 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Core.Utils 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.CustomTabs 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.v4 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Design 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.v7.AppCompat 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.v7.CardView 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Arch.Lifecycle.Runtime 1.1.1.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Collections 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Annotations 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.VersionedParcelable 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.DocumentFile 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Loader 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.LocalBroadcastManager 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Print 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Interpolator 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Core.UI 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Fragment 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Media.Compat 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.v7.RecyclerView 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Transition 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Animated.Vector.Drawable 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.Vector.Drawable 28.0.0.1 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Arch.Core.Common 1.1.1.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Arch.Lifecycle.Common 1.1.1.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Arch.Lifecycle.LiveData 1.1.1.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Arch.Lifecycle.ViewModel 1.1.1.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.AsyncLayoutInflater 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.CoordinaterLayout 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.CursorAdapter 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.CustomView 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.DrawerLayout 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.SlidingPaneLayout 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.SwipeRefreshLayout 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Support.ViewPager 28.0.0.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Arch.Core.Runtime 1.1.1.3 with MonoAndroid,Version=v9.0.
Checking compatibility for Xamarin.Android.Arch.Lifecycle.LiveData.Core 1.1.1.3 with MonoAndroid,Version=v9.0.
All packages and projects are compatible with MonoAndroid,Version=v9.0.
Package restore failed. Rolling back package changes for 'MyApp.Android'.