[英]Xamarin.Forms Android project does not compile due to strange errors
我有一个Xamarin.Forms项目,包括一个可移植类库(PCL),一个iOS应用程序和一个Android应用程序。 当我构建解决方案时,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'.
更奇怪的是,当我打开NuGet Package Manager时,我有以下组件的更新列表:
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
如果我尝试更新任何组件,我会收到以下消息:
Unable to resolve dependencies. 'Xamarin.Android.Support.Design 24.2.1' is not compatible with 'Xamarin.Forms 2.3.3.180'.
我在某处读到了我应该完全卸载它们因为我不需要它们但是如果我尝试卸载任何组件,我会收到以下错误:
Unable to uninstall 'Xamarin.Android.Support.v7.RecyclerView.23.3.0' because 'Xamarin.Android.Support.Design.23.3.0' depends on it.
如果我尝试卸载它们,即使没有任何依赖项的组件也会抛出类似的消息。 我在网上搜索过,但我似乎无法找到解决方案。 到目前为止,我尝试过以下方法:
完全重新创建项目。 由于错误继续出现,这没有帮助
删除 C:\\Users\\Admin\\AppData\\Local\\Xamarin\\
。 该解决方案根本没有消除错误。
难道我做错了什么? 我正在做的就是在Visual Studio中选择Blank Xaml App(Xamarin.Forms Portable)模板并命名我的项目。 你很难犯这个错误。 一旦我选择Build,我就会得到Android项目的所有错误。 这是Xamarin.Forms需要解决的问题吗? 有关如何解决此问题的任何建议?
在使用不同的关键字搜索互联网后,我解决了这个问题。 根据这篇文章,一些Android组件显示这些错误的原因是因为有一个损坏的ZIP下载。 这可能是因为:
取消构建过程。 如果取消Android应用程序的构建过程,则所有正在下载的文件也会被取消,从而导致文件损坏。
任何其他中断。 网络错误或无响应的IDE也可能导致此问题。
要解决此错误,我建议如下:
导航到以下目录:
C:\\Users\\User\\AppData\\Local\\Xamarin
确保Visual Studio完全关闭。 这可以通过任务管理器进行检查,以确保没有其他属于Visual Studio的进程正在运行
删除目录的内容。 如果出现任何警告对话框,请选择“跳过”并确保删除名为zips
的文件夹
打开您的项目并执行清理。 然后,您可以继续构建项目,Visual Studio将下载您删除但未损坏的相同文件
你现在应该有一个有效的应用程序!
如果问题仍然存在,请确保您已正确执行这些步骤。
您应该只更新Xamarin Forms包并单独保留Xamarin.Android。*包(表单包将为您升级它们)。
这些主题错误也可以忽略,如果你得到一个编译错误,那可能是其他错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.