I'm updating a web site and associated mobile app. The web site is going from .NET 4.6 to .NET 6. The mobile app is going from Android 8 to Android 12.
In the mobile app I converted the PCL to a .NET6 (.NETStandard) library. I'm trying to update the Xamarin.Android app by moving the project files to a new project created with the "Android Application (Preview)" project template in Visual Studio 2022. I first added all of the NuGet packages from the old Android project, upgrading all of the packages to their latest stable versions and made sure I could compile. Here are the package references:
<PackageReference Include="Acr.UserDialogs" Version="7.2.0.564" />
<PackageReference Include="Chance.MvvmCross.Plugins.UserInteraction" Version="1.1.4" />
<PackageReference Include="Cheesebaron.MvxPlugins.Connectivity" Version="6.0.0" />
<PackageReference Include="Microsoft.AppCenter.Analytics" Version="4.5.1" />
<PackageReference Include="Microsoft.AppCenter.Crashes" Version="4.5.1" />
<PackageReference Include="MvvmCross" Version="8.0.2" />
<PackageReference Include="MvvmCross.Droid.Support.Core.UI" Version="6.4.2" />
<PackageReference Include="MvvmCross.Droid.Support.V7.RecyclerView" Version="6.4.2" />
<PackageReference Include="MvvmCross.DroidX.RecyclerView" Version="8.0.2" />
<PackageReference Include="MvvmCross.DroidX.SwipeRefreshLayout" Version="8.0.2" />
<PackageReference Include="MvvmCross.Plugin.Visibility" Version="8.0.2" />
<PackageReference Include="MvvmCross.Plugin.WebBrowser" Version="8.0.2" />
<PackageReference Include="Naxam.BrainTree.Droid" Version="3.15.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Data.SQLite" Version="1.0.115.5" />
<PackageReference Include="Xam.Plugins.Settings" Version="3.1.1" />
<PackageReference Include="Xamarin.Android.Arch.Lifecycle.ViewModel" Version="1.1.1.3" />
<PackageReference Include="Xamarin.Android.Support.Annotations" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Collections" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Compat" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Core.UI" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Core.Utils" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.CursorAdapter" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.Loader" Version="28.0.0.3" />
<PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="28.0.0.3" />
<PackageReference Include="Xamarin.AndroidX.AppCompat" Version="1.4.1.1" />
<PackageReference Include="Xamarin.AndroidX.Legacy.Support.V4" Version="1.0.0.13" />
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.4.1.1" />
<PackageReference Include="Xamarin.CardIO.Android" Version="5.5.1" />
<PackageReference Include="Xamarin.Controls.SignaturePad" Version="3.0.0" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.3" />
<PackageReference Include="Xamarin.Firebase.Iid" Version="121.1.0.5" />
<PackageReference Include="Xamarin.Firebase.Messaging" Version="122.0.0.5" />
<PackageReference Include="Xamarin.Google.Android.Material" Version="1.6.0" />
<PackageReference Include="XamiTextSharpLGPLv2" Version="1.0.0" />
The error occurs once I start adding resources. Specifically, when I add the "Resources\drawable-mdpi" folder from the old project I start getting this error. Here's the partial verbose build output. The name of the Android project is "AndroidApp1" (Let me know if posting some of the 1300+ warnings would help):
Build started...
1>------ Build started: Project: AndroidApp1, Configuration: Debug Any CPU ------
1>C:\Users\peter.nuget\packages\xamarin.build.download\0.11.0\buildTransitive\Xamarin.Build.Download.targets(88,3): warning XBD100: ItemGroup XamarinBuildDownloadRestoreAssemblyAar
is no longer supported. If your build is failing, revert to an older Xamarin.Build.Download version, or migrate your packages to use the new XamarinBuildDownloadAndroidAarLibrary
ItemGroup. If your build is succeeding it is safe to ignore this warning.
1>C:\Work\Riteload\MRL-Mobile-Carrier\AndroidApp1\MrlCoreProxy\IDatabaseContextProxy.cs(18,90,18,94): warning CS8625: Cannot convert null literal to non-nullable reference type.
...
1>AndroidApp1 -> C:\Work\Riteload\MRL-Mobile-Carrier\AndroidApp1\bin\Debug\net6.0-android31.0\AndroidApp1.dll
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.14.106\targets\Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: System.InvalidOperationException: PE image does not have metadata.
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.14.106\targets\Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: at System.Reflection.PortableExecutable.PEReader.GetMetadataBlock()
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.14.106\targets\Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder)
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.14.106\targets\Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: at Xamarin.Android.Tasks.MonoAndroidHelper.HasMonoAndroidReference(ITaskItem assembly)
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.14.106\targets\Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: at Xamarin.Android.Tasks.ProcessAssemblies.SetMetadataForAssemblies(List1 output, Dictionary
2 symbols)
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.14.106\targets\Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: **at Xamarin.Android.Tasks.ProcessAssemblies.RunTask()
1>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.200-preview.14.106\targets\Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17**
1>Done building project "AndroidApp1.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
A few odd notes in case they're relevant:
- I have to build the project twice before getting the error. After the first build the project doesn't recognize the reference to the .NET6 library that was converted from
the PCL; I get missing reference errors everywhere it's used in code. After the second build, the missing reference errors go away and I get the single "PE image does
not have metadata" error.
- The compiler produces a .dll when the error occurs but I get the error again when I try to run it in the VS Android emulator.
Is there actually a problem with the images? Is the drawable-mdpi folder invalid in Android 12? Is this caused by the update?
Thank you in advance.