Xamarin: 没有找到与给定名称(AppCompat)匹配的资源。

17

我在Azure上部署了一个虚拟机。 我安装了Visual Studio 2015、Xamarin和其他移动开发工具。我在本地计算机上进行了相同的设置,以便从Visual Studio测试我的应用程序。

唯一的区别是Android SDK的安装。 在我的本地计算机上,我没有映像系统。

Android DSK Manager

我在虚拟机上开发了一个应用程序。 编译期间没有错误。我使用了Android.Support.Design、Android.Support.V4、Android.Support.V7.AppCompat、Android.Support.V7.RecyclerView(来自NuGet的最新版本)及其MvvmCross实现。

My Azure Virtual Machine

我想在本地计算机上继续开发这个应用程序。 NuGet包已正确还原。

但当我构建应用程序时,出现了一些错误:

My Local Machine

Error       Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.  Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       Error retrieving parent for item: No resource found that matches the given name 'Base.Widget.AppCompat.Button'. Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       No resource found that matches the given name: attr 'buttonStyle'.  Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       No resource found that matches the given name: attr 'colorAccent'.  Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       No resource found that matches the given name: attr 'colorPrimary'. Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       No resource found that matches the given name: attr 'colorPrimaryDark'. Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       No resource found that matches the given name: attr 'windowActionBar'.  Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       No resource found that matches the given name: attr 'windowNoTitle'.    Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml
Error       No resource found that matches the given name: attr 'windowNoTitle'.    Novatech.Droid  D:\Sources\Novatech\Novatech.Droid\Resources\values\styles.xml

我尝试过:

  • 将'Theme.AppCompat.Light.DarkActionBar'更改为'@android:styles/Theme.AppCompat.Light.DarkActionBar',以及其他一些(android/styles)
  • C:\Program Files (x86)\Android\android-sdk\extras\android\support\v7\appcompat\project.properties中将target=android-19更改为target=android-21

有人能解释一下问题吗?我放弃了。操作系统、工具、SDK和JDK都是相同的。


请清理并重新构建您的项目。 - BYISHIMO Audace
15个回答

0

我在将项目从一个文件夹移动到另一个文件夹后遇到了同样的问题,而且是在同一台笔记本电脑上。通过反复尝试,我最终解决了这个问题,但仍然不知道问题的原因。解决它需要多次清理解决方案并重新启动Visual Studio。


0

我从Xamarin组件切换到NuGet包,现在它可以工作了。 MvvmCross安装了最新版本的Nuget包(23.3.0)用于其依赖项(MvvmCross.Droid.Support.V4、MvvmCross.Droid.Support.V7.AppCompat、MvvmCross.Droid.Support.V7.Preference...)和之前使用的组件。

我还不得不从我的虚拟机中复制“C:\Users\andres\AppData\Local\Xamarin”文件夹。

在Visual Studio中,我没有收到有关组件可用更新的通知。


0
清除AppData中的缓存文件可能会有所帮助。
C:\Users\Your-User-name\AppData\Local\Xamarin.Android

0

我在处理样式时遇到了引用属性的错误,所以将attrs.xml重命名为Attrs.xml(然后在进行干净的重建后再改回来)。


0

我在使用虚拟机上的MSBuild时遇到了类似的问题。我正在尝试构建一个Xamarin Android项目,但是它一直报错并显示“error retrieving parent for item theme.appcompat.light.darkactionbar.” 的信息。不过,我通过添加参数 /t:restore 来解决了这个问题 - 例如:

msbuild  /t:SignAndroidPackage /t:restore /p:Configuration=Release <project path>

注意,第一次使用还原参数运行它仍然失败了,但当我尝试再次构建时它成功了。希望这能帮助到某些人 - 我花了几个小时来正确配置MSBuild!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接