c# - 由于出现奇怪的错误,Xamarin.Forms Android 项目无法编译

标签 c# xamarin.android xamarin.forms

我有一个 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 包管理器时,我有以下组件的更新列表:

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.

如果我尝试卸载那些没有任何 依赖项的组件,它们也会抛出类似的消息。我在网上搜索过,但似乎仍然找不到解决方案。到目前为止,我已经尝试了以下方法:

  1. 完全重新创建项目。这没有帮助,因为错误继续出现

  2. 删除C:\Users\Admin\AppData\Local\Xamarin\的内容。这个解决方案没有完全消除错误。

我做错了什么吗?我所做的只是在 Visual Studio 中选择 Blank Xaml App (Xamarin.Forms Portable) 模板并命名我的项目。你几乎不会在这方面犯错。一旦我选择构建,我就会得到 Android 项目的所有错误。这是需要解决的 Xamarin.Forms 问题吗?关于如何解决这个问题有什么建议吗?

最佳答案

在网上用不同的关键字搜索后,我解决了这个问题。根据this发布,某些 Android 组件显示这些错误的原因是因为存在损坏的 ZIP 下载。这可能是因为:

  • 取消构建过程。如果您取消 Android 应用程序的构建过程,所有正在下载的文件也会被取消,从而导致文件损坏。

  • 任何其他中断。网络错误或无响应的 IDE 也可能导致此问题。

为了解决这个错误,我建议如下:

  1. 导航到以下目录:

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

  2. 确保 Visual Studio 已完全关闭。这可以通过任务管理器进行检查,以确保没有属于 Visual Studio 的其他进程正在运行

  3. 删除目录的内容。如果出现任何警告对话框,请选择“跳过”并确保删除名为 zips 的文件夹

    <
  4. 打开您的项目并执行清理。然后您可以继续构建您的项目,Visual Studio 将下载您删除的未损坏的相同文件

  5. 您现在应该有一个可以工作的应用程序!

如果问题仍然存在,请确保您已正确执行这些步骤。

关于c# - 由于出现奇怪的错误,Xamarin.Forms Android 项目无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41776130/

相关文章:

android - Xamarin for Android:无法从外部文件夹播放mp3

android - “No system images installed for this target” Xamarin AVD 管理器

data-binding - Xamarin.Forms 中标签 StringFormat 的本地化

c# - Xamarin 表格 : StackLayout inside RelativeLayout is not filling the whole screen

c# - 如何放大和缩小WP7中的图片?

c# - ASP.NET 脚本 "scheduling"问题

c# - 另一个进程正在使用文件。原因,解决方案?

c# - 如何将 visual studio 2010 解决方案构建到独立的 dll 中?

xamarin - Java.lang.NoClassDefFoundError使用Android支持设计NavigationView时出现问题

visual-studio - 如何修复错误 NU1202 包 Xamarin.Android.Support.CustomTabs