Xamarin.Forms 5.0.0.2622 关于 styles.xml 的编译错误

问题描述 投票:0回答:1

在具有最新更新的 MacOS Sonoma 上使用 Jetbrains Rider。

升级到 Xamarin.Forms 5.0.0.2622(以及我升级的所有其他包)后,开始出现以下错误:

0>styles.xml(13): Error APT2260 : style attribute 'attr/colorAccent (aka com.ScanAndBroadcastSample:attr/colorAccent)' not found.
0>Xamarin.Android.Aapt2.targets(156,3): Error APT2260 : resource style/Theme.AppCompat.DayNight.DarkActionBar (aka com.ScanAndBroadcastSample:style/Theme.AppCompat.DayNight.DarkActionBar) not found.
0>styles.xml(11): Error APT2260 : style attribute 'attr/windowNoTitle (aka com.ScanAndBroadcastSample:attr/windowNoTitle)' not found.
0>styles.xml(11): Error APT2260 : style attribute 'attr/windowActionBar (aka com.ScanAndBroadcastSample:attr/windowActionBar)' not found.
0>styles.xml(11): Error APT2260 : style attribute 'attr/colorPrimary (aka com.ScanAndBroadcastSample:attr/colorPrimary)' not found.
0>styles.xml(11): Error APT2260 : style attribute 'attr/colorPrimaryDark (aka com.ScanAndBroadcastSample:attr/colorPrimaryDark)' not found.
0>styles.xml(12): Error APT2260 : style attribute 'attr/colorAccent (aka com.ScanAndBroadcastSample:attr/colorAccent)' not found.
0>styles.xml(13): Error APT2260 : style attribute 'attr/windowActionModeOverlay (aka com.ScanAndBroadcastSample:attr/windowActionModeOverlay)' not found.
0>Xamarin.Android.Aapt2.targets(156,3): Error APT2062 : failed linking references.

我的软件包(撰写本文时的最新版本为 2023 年第 3 季度):

    <PackageReference Include="Xamarin.CommunityToolkit" Version="2.0.6" />
    <PackageReference Include="Xamarin.Essentials" Version="1.8.0" />
    <PackageReference Include="Xamarin.Forms" Version="5.0.0.2622" />
    <PackageReference Include="Xamarin.AndroidX.Browser" Version="1.6.0" />
    <PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.21" />
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.6.2.2" />
    <PackageReference Include="Xamarin.Google.Android.Material" Version="1.10.0.1" />

xamarin/android.csproj 中的设置:

    <TargetFrameworks>monoandroid13.0;</TargetFrameworks>
    <TargetFrameworkVersion>v13.0</TargetFrameworkVersion>

样式.xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>

    <style name="MainTheme" parent="MainTheme.Base">
    </style>

</resources>

Rider 中使用的 JDK 位置:

% /Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home/bin/java --version
openjdk 11.0.16.1 2022-08-12 LTS
OpenJDK Runtime Environment Microsoft-40648 (build 11.0.16.1+1-LTS)
OpenJDK 64-Bit Server VM Microsoft-40648 (build 11.0.16.1+1-LTS, mixed mode)

我尝试过的事情(实际上 stackoverflow 中给出的任何建议):

  • 清理 nuget 缓存并从头开始重新获取所有内容
  • 重新安装 Android JDK(API 级别 30 到 34)
  • 尝试使用 VS2022 和 Jetbrains Rider 进行构建
  • 将软件包降级到不同版本
  • 清理 bin 和 obj 文件夹并从头开始重建项目
  • 使用“@android:style”语法

没有任何帮助。给什么?

c# android .net xamarin
1个回答
0
投票

升级到后,以下错误开始出现 Xamarin.Forms 5.0.0.2622(以及我的所有其他包) 升级):

0>styles.xml(13):错误 APT2260:样式属性“attr/colorAccent” (又名 com.ScanAndBroadcastSample:attr/colorAccent)' 未找到。 0>Xamarin.Android.Aapt2.targets(156,3):错误 APT2260:找不到资源样式/Theme.AppCompat.DayNight.DarkActionBar(又名 com.ScanAndBroadcastSample:style/Theme.AppCompat.DayNight.DarkActionBar)。 ......................

关于这个错误你可以参考Brandon Minnick的这个案例:Xamarin.Forms 5.0.0.2612 Breaks Android Build: Error APT2260: resource style/Theme.AppCompat.Light.Dialog not found.

并尝试更新此文件:

AndroidManifest.xml

AndroidManifest.xml
(又名 Android 清单)中,将
android:targetSdkVersion
更新为
"33"

<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />
© www.soinside.com 2019 - 2024. All rights reserved.