Jacob Ernst
Jacob Ernst

Reputation: 107

NuGet package install fails "Package restore failed. Rolling back package changes for <xamarin.android>"

Installing any package fails with this error, updating packages also creates this error. Clearing the NuGet cache files causes this error to change to "access to the path mono.cecil.dll is denied" when trying to install "Xamarin.GooglePlayServices.Ads". Restarting visual studio causes the package restore error to come back.

  1. Versions:

  2. Xamarin.Forms Project:

    • Target framework: .NET 2.0
  3. Xamarin.Android project:

    • Minimum Android Version: 5.0 (API Level 21)
    • Target Android Version: Use Compile Using SDK version (8.0)

Upvotes: 1

Views: 4065

Answers (2)

Janaco
Janaco

Reputation: 1683

I faced the same error when I was trying to update the libraries one by one. Then I tried selecting all required libraries and clicked the Update button bellow the search box and it works. I have to tell that these libraries had dependencies between each other.
Here's an example:
enter image description here

Upvotes: 0

Jacob Ernst
Jacob Ernst

Reputation: 107

Well after some trial and error I have the solution.

  1. Visual Studio:

    • Update visual studio https://pastebin.com/GkEeRqg3
      • Updates Xamarin.Forms and NuGet
    • Repair visual studio from the "Visual Studio installer"
      • This Fixes the access denied to *.dll error
  2. Xamarin.Android project:

    • Set Target Android Version: 8.1 API 27
      • This makes the packages the require monoandroid81 happy.
  3. Cleaning house

    • Delete the folder C:\Users\<Your_Name>\AppData\Local\Xamarin`
      • Not sure if this was necessary but I am documenting anything I did so others can replicate the solution.
  4. Fixing NuGet

    • Right-click <Project_name>.android --> Set as startup project.
    • Tools --> NuGet Package Manager --> Package Manager Console
    • In the console CLI run Update-Package -Reinstall

Why did this happen?

One way or another some of the NuGet packages used in Xamarin.Android used monoandroid81. Even though my solution was set to use 80 some NuGet packages installed were only compatible with 81.
This was shown in the NuGet Console. Package Xamarin.Android.Support.v7.MediaRouter 27.0.2 is not compatible with monoandroid80 (MonoAndroid,Version=v8.0). Package Xamarin.Android.Support.v7.MediaRouter 27.0.2 supports: monoandroid81 (MonoAndroid,Version=v8.1)

Upvotes: 3

Related Questions