简体   繁体   English

Xamarin.Forms Android项目由于奇怪的错误而无法编译

[英]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. 我有一个Xamarin.Forms项目,包括一个可移植类库(PCL),一个iOS应用程序和一个Android应用程序。 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: 当我构建解决方案时,PCL和iOS项目成功构建,但Android应用程序根本没有构建,因为下面列出了几个奇怪的错误:

 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: 更奇怪的是,当我打开NuGet Package Manager时,我有以下组件的更新列表:

Xamarin.Android.Support.Design Xamarin.Android.Support.Design
Xamarin.Android.Support.v4 Xamarin.Android.Support.v4
Xamarin.Android.Support.v7.AppCompat Xamarin.Android.Support.v7.AppCompat
Xamarin.Android.Support.v7.CardView Xamarin.Android.Support.v7.CardView
Xamarin.Android.Support.v7.MediaRouter Xamarin.Android.Support.v7.MediaRouter
Xamarin.Android.Support.v7.RecyclerView 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\\ . 删除 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. 我正在做的就是在Visual Studio中选择Blank Xaml App(Xamarin.Forms Portable)模板并命名我的项目。 You can hardly make a mistake in that. 你很难犯这个错误。 As soon as I select Build, I get all the errors for the Android project. 一旦我选择Build,我就会得到Android项目的所有错误。 Is this a problem with Xamarin.Forms that needs to be addressed? 这是Xamarin.Forms需要解决的问题吗? 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. 根据这篇文章,一些Android组件显示这些错误的原因是因为有一个损坏的ZIP下载。 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. 如果取消Android应用程序的构建过程,则所有正在下载的文件也会被取消,从而导致文件损坏。

  • Any other interruptions. 任何其他中断。 Network errors or an unresponsive IDE could also result in this issue. 网络错误或无响应的IDE也可能导致此问题。

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. 确保Visual Studio完全关闭。 This can be checked via Task Manager to ensure no other processes belonging to Visual Studio are running 这可以通过任务管理器进行检查,以确保没有其他属于Visual Studio的进程正在运行

  3. Delete the contents of the directory. 删除目录的内容。 If any warning dialogs appear, select Skip and ensure that a folder called zips is deleted 如果出现任何警告对话框,请选择“跳过”并确保删除名为zips的文件夹

  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 然后,您可以继续构建项目,Visual Studio将下载您删除但未损坏的相同文件

  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). 您应该只更新Xamarin Forms包并单独保留Xamarin.Android。*包(表单包将为您升级它们)。

Also those theme errors can be ignored, if your getting a compile error it is probably something else that is wrong. 这些主题错误也可以忽略,如果你得到一个编译错误,那可能是其他错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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