Skip to content

Exception with Aapt MSBuild task #1456

Description

@garuma

Compiling an Android project I get the following exception:

_SetLatestTargetFrameworkVersion:
  Found Java SDK version 1.8.0.
_ResolveMonoAndroidSdks:
  MonoAndroid Tools: C:\Program Files (x86)\Microsoft Visual Studio\Dogfood\Enterprise\MSBuild\Xamarin\Android\
  Android Platform API level: 27
  TargetFrameworkVersion: v8.1
  Android NDK: C:\Program Files (x86)\Android\android-ndk-r12b\
  Android SDK: C:\Program Files (x86)\Android\android-sdk\
  Android SDK Build Tools: C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\
  Java SDK: C:\Program Files\Java\jdk1.8.0_161\
_GetPrimaryCpuAbi:
  _PrimaryCpuAbi=
_CheckInstantRunCondition:
  Dex Fast Deployment Enabled: False
_SetupInstantRun:
  Android Java Class for Fast Deployment:
_SetupApplicationJavaClass:
  Application Java class: android.app.Application
_ValidateAndroidPackageProperties:
    PackageName: AndroidCustomControlsClass.AndroidCustomControlsClass
_ResolveLibraryProjectImports:
Skipping target "_ResolveLibraryProjectImports" because all output files are up-to-date with respect to the input files.
_BuildLibraryImportsCache:
Skipping target "_BuildLibraryImportsCache" because all output files are up-to-date with respect to the input files.
_BuildAdditionalResourcesCache:
Skipping target "_BuildAdditionalResourcesCache" because all output files are up-to-date with respect to the input files.
_CreateAdditionalResourceCache:
Skipping target "_CreateAdditionalResourceCache" because it has no outputs.
_GenerateAndroidResourceDir:
Skipping target "_GenerateAndroidResourceDir" because all output files are up-to-date with respect to the input files.
_GenerateCodeBehindForLayout:
Skipping target "_GenerateCodeBehindForLayout" because it has no outputs.
_DefineBuildTargetAbis:
  Build target ABI: arm64-v8a;armeabi;armeabi-v7a;x86;x86_64
_UpdateAndroidResgen:
Skipping target "_UpdateAndroidResgen" because all output files are up-to-date with respect to the input files.
_CreateManagedLibraryResourceArchive:
Skipping target "_CreateManagedLibraryResourceArchive" because all output files are up-to-date with respect to the input files.
_CreateAdditionalResourceCache:
Skipping target "_CreateAdditionalResourceCache" because it has no outputs.
_GenerateJavaDesignerForComponent:
Skipping target "_GenerateJavaDesignerForComponent" because it has no inputs.
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
  AndroidCustomControlsClass -> C:\Git\designer\Xamarin.Designer.Android\Xamarin.AndroidDesigner.Tests\AndroidCustomControlsClass\bin\Debug\AndroidCustomControlsClass.dll
Done Building Project "C:\Git\designer\Xamarin.Designer.Android\Xamarin.AndroidDesigner.Tests\AndroidCustomControlsClass\AndroidCustomControlsClass.csproj" (default targets).

_ResolveMonoAndroidSdks:
  MonoAndroid Tools: C:\Program Files (x86)\Microsoft Visual Studio\Dogfood\Enterprise\MSBuild\Xamarin\Android\
  Android Platform API level: 27
  TargetFrameworkVersion: v8.1
  Android NDK: C:\Program Files (x86)\Android\android-ndk-r12b\
  Android SDK: C:\Program Files (x86)\Android\android-sdk\
  Android SDK Build Tools: C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\
  Java SDK: C:\Program Files\Java\jdk1.8.0_161\
_GetPrimaryCpuAbi:
  _PrimaryCpuAbi=
_CheckInstantRunCondition:
  Dex Fast Deployment Enabled: False
_SetupInstantRun:
  Android Java Class for Fast Deployment:
_SetupApplicationJavaClass:
  Application Java class: android.app.Application
_ResolveLibraryProjectImports:
Skipping target "_ResolveLibraryProjectImports" because all output files are up-to-date with respect to the input files.
_BuildLibraryImportsCache:
Skipping target "_BuildLibraryImportsCache" because all output files are up-to-date with respect to the input files.
_BuildAdditionalResourcesCache:
Skipping target "_BuildAdditionalResourcesCache" because all output files are up-to-date with respect to the input files.
_CreateAdditionalResourceCache:
Skipping target "_CreateAdditionalResourceCache" because it has no outputs.
_GenerateAndroidResourceDir:
Skipping target "_GenerateAndroidResourceDir" because all output files are up-to-date with respect to the input files.
_GenerateCodeBehindForLayout:
Skipping target "_GenerateCodeBehindForLayout" because it has no outputs.
_DefineBuildTargetAbis:
  Build target ABI: arm64-v8a;armeabi;armeabi-v7a;x86;x86_64
VectorDrawableCheckBuildToolsVersionTask:
  Checking Android SDK Build-tools version...
  Selected Android SDK Build Tools Path: C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\
  Selected Android SDK Build Tools Version: 27.0.3
  Android SDK Build Tools Version: 27.0.3 meets minimum requirements for Vector Drawables. OK.
  Finished Checking Android SDK Build-tools version.

Unhandled Exception: System.ArgumentOutOfRangeException: capacity was less than the current size.
Parameter name: value
   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.set_Capacity(Int32 value)
   at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
   at System.Collections.Generic.List`1.Add(T item)
   at Xamarin.Android.Tasks.Aapt.<>c__DisplayClass134_0.<RunAapt>b__0(Object sender, DataReceivedEventArgs e)
   at System.Diagnostics.Process.OutputReadNotifyUser(String data)
   at System.Diagnostics.AsyncStreamReader.FlushMessageQueue()
   at System.Diagnostics.AsyncStreamReader.GetLinesFromStringBuilder()
   at System.Diagnostics.AsyncStreamReader.ReadBuffer(IAsyncResult ar)
   at System.IO.Stream.ReadWriteTask.InvokeAsyncCallback(Object completedTask)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.IO.Stream.ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke(Task completingTask)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean bUserDelegateExecuted)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
   at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

It seems like it could be possible in the current code both handler to Process could be run at the same time on different threading causing this issue: https://github.com/xamarin/xamarin-android/blob/1826ec21d5ac9e64d53896ad9cc24c53b5afb3d5/src/Xamarin.Android.Build.Tasks/Tasks/Aapt.cs#L131-L142

Tested on 15-7 Visual Studio/MSBuild builds with Xamarin.Android from 1a8ed53884354fd57ba486aa4dda09538e7e722b

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: App+Library BuildIssues when building Library projects or Application projects.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions