Tuesday, 27 September 2022

VS Xamarin build blowing up in Android DLL - unable to build - Android.dll getting IndexOutOfRangeException

I have a VS 2022 Windows Xamarin Forms application that has been working successfully on Android and UWP. I have started working with a cloud Mac service to build an iOS version. I have tweaked a couple of things the way you do when you are trying to get something new to work, but I don't know what I might have done to cause this. Obviously I know what a basic OutOfRangeException is, but I have no idea how to solve this or even really what to look for.

Perhaps the problem occurred with the VS 2022 17.3.4 update.

The problem occurs during the build, not when running my code, so I have no idea where or how to look for the problem.

I tried unloading the iOS project but the error still occurs.

Here are the complete errors

Severity    Code    Description Project File    Line    Suppression State
Error       System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Xamarin.Android.Tasks.GeneratePackageManagerJava.<>c__DisplayClass131_0.<AddEnvironment>g__AddEnvironmentVariable|2(String name, String value)
   at Xamarin.Android.Tasks.GeneratePackageManagerJava.AddEnvironment()
   at Xamarin.Android.Tasks.GeneratePackageManagerJava.RunTask()
   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 KhyberPassWithUWP2.Android          
Severity    Code    Description Project File    Line    Suppression State
Error       XAGPM7006: System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Xamarin.Android.Tasks.GeneratePackageManagerJava.<>c__DisplayClass131_0.<AddEnvironment>g__AddEnvironmentVariable|2(String name, String value)
   at Xamarin.Android.Tasks.GeneratePackageManagerJava.AddEnvironment()
   at Xamarin.Android.Tasks.GeneratePackageManagerJava.RunTask()
   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         0   

and here is what might be the relevant code from Xamarin.Android.Common.targets

<Target Name="_GeneratePackageManagerJava"
  DependsOnTargets="$(_GeneratePackageManagerJavaDependsOn)"
  Inputs="@(_AndroidMSBuildAllProjects);$(_ResolvedUserAssembliesHashFile);$(MSBuildProjectFile);$(_AndroidBuildPropertiesCache);@(AndroidEnvironment);@(LibraryEnvironments)"
  Outputs="$(_AndroidStampDirectory)_GeneratePackageManagerJava.stamp">
  <!-- Create java needed for Mono runtime -->
  <GeneratePackageManagerJava
    ResolvedAssemblies="@(_ResolvedAssemblies)"
    ResolvedUserAssemblies="@(_ResolvedUserAssemblies)"
    SatelliteAssemblies="@(_AndroidResolvedSatellitePaths)"
    NativeLibraries="@(AndroidNativeLibrary);@(EmbeddedNativeLibrary);@(FrameworkNativeLibrary)"
    MonoComponents="@(_MonoComponent)"
    MainAssembly="$(TargetPath)"
    OutputDirectory="$(_AndroidIntermediateJavaSourceDirectory)mono"
    EnvironmentOutputDirectory="$(IntermediateOutputPath)android"
    TargetFrameworkVersion="$(TargetFrameworkVersion)"
    Manifest="$(IntermediateOutputPath)android\AndroidManifest.xml"
    Environments="@(AndroidEnvironment);@(LibraryEnvironments)"
    AndroidAotMode="$(AndroidAotMode)"
    AndroidAotEnableLazyLoad="$(AndroidAotEnableLazyLoad)"
    EnableLLVM="$(EnableLLVM)"
    HttpClientHandlerType="$(AndroidHttpClientHandlerType)"
    TlsProvider="$(AndroidTlsProvider)"
    Debug="$(AndroidIncludeDebugSymbols)"
    AndroidSequencePointsMode="$(_SequencePointsMode)"
    EnableSGenConcurrent="$(AndroidEnableSGenConcurrent)"
    IsBundledApplication="$(BundleAssemblies)"
    SupportedAbis="@(_BuildTargetAbis)"
    AndroidPackageName="$(_AndroidPackage)"
    EnablePreloadAssembliesDefault="$(_AndroidEnablePreloadAssembliesDefault)"
    PackageNamingPolicy="$(AndroidPackageNamingPolicy)"
    BoundExceptionType="$(AndroidBoundExceptionType)"
    InstantRunEnabled="$(_InstantRunEnabled)"
    RuntimeConfigBinFilePath="$(_BinaryRuntimeConfigPath)"
    UsingAndroidNETSdk="$(UsingAndroidNETSdk)"
    UseAssemblyStore="$(AndroidUseAssemblyStore)"
  >
    <Output TaskParameter="BuildId" PropertyName="_XamarinBuildId" />
  </GeneratePackageManagerJava>
  <Touch Files="$(_AndroidStampDirectory)_GeneratePackageManagerJava.stamp" AlwaysCreate="True" />
  <WriteLinesToFile
      File="$(_AndroidBuildIdFile)"
      Lines="$(_XamarinBuildId)"
      Overwrite="true"
      WriteOnlyWhenDifferent="true"
  />


from VS Xamarin build blowing up in Android DLL - unable to build - Android.dll getting IndexOutOfRangeException

No comments:

Post a Comment