简体   繁体   中英

Xamarin.Forms Android project does not compile due to strange errors

I have a Xamarin.Forms project that consists of a Portable Class Library (PCL), an iOS application and an Android application. When I build the solution, the PCL and the iOS projects build successfully, but the Android application doesn't build at all due to several strange errors as listed below:

 error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. error APT0000: No resource found that matches the given name: attr 'colorAccent'. error APT0000: No resource found that matches the given name: attr 'colorPrimary'. error APT0000: No resource found that matches the given name: attr 'colorPrimaryDark'. error APT0000: No resource found that matches the given name: attr 'windowActionBar'. error APT0000: No resource found that matches the given name: attr 'windowActionModeOverlay'. error APT0000: No resource found that matches the given name: attr 'windowNoTitle'. error APT0000: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.Dialog'. error APT0000: No resource found that matches the given name: attr 'colorAccent'. 

What's even stranger is when I open NuGet Package Manager, I have a list of updates for the following components:

Xamarin.Android.Support.Design
Xamarin.Android.Support.v4
Xamarin.Android.Support.v7.AppCompat
Xamarin.Android.Support.v7.CardView
Xamarin.Android.Support.v7.MediaRouter
Xamarin.Android.Support.v7.RecyclerView

If I try to update any of the components, I get the following message:

Unable to resolve dependencies. 'Xamarin.Android.Support.Design 24.2.1' is not compatible with 'Xamarin.Forms 2.3.3.180'.

I read somewhere that I should uninstall them completely because I won't have any need for them but if I try to uninstall any of the components, I get the following error:

Unable to uninstall 'Xamarin.Android.Support.v7.RecyclerView.23.3.0' because 'Xamarin.Android.Support.Design.23.3.0' depends on it.

Even the components that don't have any dependencies throw out a similar message if I try to uninstall them. I have searched online but I still can't seem to find a solution. So far, I have tried the following:

  1. Recreating the project completely. This didn't help as the errors continued to appear

  2. Deleting the contents of C:\\Users\\Admin\\AppData\\Local\\Xamarin\\ . This solution didn't remove the errors at all.

Am I doing something wrong? All I'm doing is selecting the Blank Xaml App (Xamarin.Forms Portable) template in Visual Studio and naming my project. You can hardly make a mistake in that. As soon as I select Build, I get all the errors for the Android project. Is this a problem with Xamarin.Forms that needs to be addressed? Any suggestions on how to solve this issue?

After searching the Internet using different keywords, I solved this issue. According to this post, the reason why some of the Android components were displaying those errors was because there was a corrupt ZIP download. This could happen because of:

  • Cancelling the build process. If you cancel the build process for your Android application, any files being downloaded are also cancelled, resulting in corrupt files.

  • Any other interruptions. Network errors or an unresponsive IDE could also result in this issue.

To solve this error, I would advise the following:

  1. Navigate to the following directory:

    C:\\Users\\User\\AppData\\Local\\Xamarin

  2. Ensure that Visual Studio is completely closed. This can be checked via Task Manager to ensure no other processes belonging to Visual Studio are running

  3. Delete the contents of the directory. If any warning dialogs appear, select Skip and ensure that a folder called zips is deleted

  4. Open up your project and perform a cleanup. You can then go ahead and build your project and Visual Studio will download the same files you deleted that aren't corrupted

  5. You should now have a working application!

If the problem continues, please ensure you have followed these steps correctly.

You should only update the Xamarin Forms package and leave the Xamarin.Android.* packages alone (the forms package will upgrade them for you).

Also those theme errors can be ignored, if your getting a compile error it is probably something else that is wrong.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM