更新到 Xamarin.Forms v5.0.0.2612 后,我的 Xamarin.Android 应用程序构建失败,并出现以下编译器错误:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(156,3): error APT2260: resource style/Theme.AppCompat.Light.Dialog (aka com.minnick.HackerNews:style/Theme.AppCompat.Light.Dialog) not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
Resources\values\styles.xml(4): error APT2260: style attribute 'attr/colorAccent (aka com.minnick.HackerNews:attr/colorAccent)' not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(156,3): error APT2260: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.minnick.HackerNews:style/Theme.AppCompat.Light.DarkActionBar) not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
Resources\values\styles.xml(2): error APT2260: style attribute 'attr/windowNoTitle (aka com.minnick.HackerNews:attr/windowNoTitle)' not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
Resources\values\styles.xml(2): error APT2260: style attribute 'attr/windowActionBar (aka com.minnick.HackerNews:attr/windowActionBar)' not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
Resources\values\styles.xml(2): error APT2260: style attribute 'attr/colorPrimary (aka com.minnick.HackerNews:attr/colorPrimary)' not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
Resources\values\styles.xml(2): error APT2260: style attribute 'attr/colorPrimaryDark (aka com.minnick.HackerNews:attr/colorPrimaryDark)' not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
Resources\values\styles.xml(3): error APT2260: style attribute 'attr/colorAccent (aka com.minnick.HackerNews:attr/colorAccent)' not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
Resources\values\styles.xml(4): error APT2260: style attribute 'attr/windowActionModeOverlay (aka com.minnick.HackerNews:attr/windowActionModeOverlay)' not found. [D:\a\1\s\sample\HackerNews.Droid\HackerNews.Droid.csproj]
我从 Xamarin.Forms v5.0.0.2612 进行更新,并且没有对我的代码进行任何更改(在 Xamarin.Forms v5.0.0.2612 上成功编译),因此不应有任何重大更改。此版本的 Xamarin.Forms 是否有问题?
在 Xamarin.Forms v5.0.0 Service Release 15 的发行说明中,他们提到它现在针对的是 Android 33:
目标 MonoAndroid13.0 by @jfversluis in解决方案
Xamarin.Android CSPROJ
csproj
文件(通常名为
*.Droid.csproj
或
*.Android.csproj
)中,将
<TargetFrameworkVersion>
更新为
v13.0
:
<TargetFrameworkVersion>v13.0</TargetFrameworkVersion>
AndroidManifest.xmlAndroidManifest.xml
(又名 Android 清单)中,将
android:targetSdkVersion
更新为
"33"
:
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="33" />