Unity 2021.2.0f1 not building for iOS

Exception: Unity.IL2CPP.Building.BuilderFailedException: Build failed with 0 successful nodes and 1 failed ones

Annotation: IL2CPP_CodeGen /Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/buildstate/artifacts/il2cpp_conv_51a0.traceevents

Cmdline: “/Applications/Unity/Hub/Editor/2021.2.0f1/Unity.app/Contents/il2cpp/build/deploy/il2cpp” --convert-to-cpp --directory=“/Users/christianroder/Documents/Kunden/…/Temp/StagingArea/Data/Managed” --data-folder=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/il2cppOutput/Data” --generatedcppdir=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/il2cppOutput” --symbols-folder=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/il2cppOutput/Symbols” --additional-cpp=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/additionalCppFiles/UnityClassRegistration.cpp” --additional-cpp=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/additionalCppFiles/UnityICallRegistration.cpp” --emit-null-checks --enable-array-bounds-check --code-generation-option=EnableInlining --generics-option=None,EnableFullSharing --stats-output-dir=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/il2cppOutput” --dotnetprofile=unityaot-macos --cachedirectory=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS” --profiler-report --profiler-output-file=“/Users/christianroder/Documents/Kunden/…/Library/Il2cppBuildCache/iOS/buildstate/artifacts/il2cpp_conv_51a0.traceevents”

ExitCode: 1

Stdout:

Error: IL2CPP error for method ‘T System.ReadOnlySpan`1::get_Item(System.Int32)’ in assembly ‘/Users/christianroder/Documents/Kunden/…/Temp/StagingArea/Data/Managed/mscorlib.dll’

System.ArgumentException: An item with the same key has already been added. Key: ReadOnlySpan_1_get_Item_mDD3167C23F8FF8ADA2554C3346F605D0C778F69E_MetadataUsageId

at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) in System.Private.CoreLib.dll:token 0x6006ab9+0x1a0

at Unity.IL2CPP.CodeWriters.InMemoryGeneratedMethodCodeWriter.AddMetadataUsage(String identifier, MethodMetadataUsage usage) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/CodeWriters/InMemoryGeneratedMethodCodeWriter.cs:line 27

at Unity.IL2CPP.CodeWriters.CodeWriterExtensions.WriteMethodWithMetadataInitialization(IGeneratedMethodCodeWriter writer, String methodSignature, Action`2 writeMethodBody, String uniqueIdentifier, MethodReference methodRef, Boolean writingMethodBody) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/CodeWriters/CodeWriterExtensions.cs:line 198

at Unity.IL2CPP.MethodWriter.WriteMethodDefinition(AssemblyWriteContext context, IGeneratedMethodCodeWriter writer, MethodReference method) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/MethodWriter.cs:line 63

at Unity.IL2CPP.SourceWriter.WriteType(SourceWritingContext context, IGeneratedMethodCodeWriter writer, TypeReference type, NPath filePath, Boolean writeMarshalingDefinitions) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/SourceWriter.cs:line 31

at Unity.IL2CPP.SourceWriters.SourceWriterBase2.WriteItem(StreamWorkItemData2 data) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/SourceWriters/SourceWriterBase.cs:line 91

at Unity.IL2CPP.Contexts.Scheduling.Streams.FileLevelParallelStreamManager3.WorkerWriteItemsToFile(WorkItemData2 data) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/Contexts.Scheduling.Streams/FileLevelParallelStreamManager.cs:line 28

at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/Contexts.Scheduling/PhaseWorkScheduler.cs:line 287

Error: IL2CPP error (no further information about what managed code was being converted is available)

System.InvalidOperationException: Failed to compare two elements in the array.

—> System.ArgumentException: Unhandled compare for

T System.ReadOnlySpan`1::get_Item(System.Int32)

and

T System.ReadOnlySpan`1::get_Item(System.Int32)

Assembly Qualified Names were

!0 System.ReadOnlySpan`1, mscorlib::get_Item(System.Int32, mscorlib)

and

!0 System.ReadOnlySpan`1, mscorlib::get_Item(System.Int32, mscorlib)

at Unity.IL2CPP.DataModel.Awesome.Ordering.OrderingCompareExtensions.ThrowFailureException(String xToString, String yToString, String xAssemblyQualifiedName, String yAssemblyQualifiedName) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/Awesome/Ordering/OrderingCompareExtensions.cs:line 677

at Unity.IL2CPP.DataModel.Awesome.Ordering.OrderingCompareExtensions.Compare(MethodDefinition x, MethodDefinition y) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/Awesome/Ordering/OrderingCompareExtensions.cs:line 595

at Unity.IL2CPP.DataModel.Awesome.Ordering.OrderingCompareExtensions.Compare(MethodReference x, MethodReference y) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP.DataModel/Awesome/Ordering/OrderingCompareExtensions.cs:line 542

at System.Collections.Generic.ArraySortHelper1.PickPivotAndPartition(Span1 keys, Comparison`1 comparer) in System.Private.CoreLib.dll:token 0x6006a1f+0x4a

at System.Collections.Generic.ArraySortHelper1.IntroSort(Span1 keys, Int32 depthLimit, Comparison`1 comparer) in System.Private.CoreLib.dll:token 0x6006a1e+0x68

at System.Collections.Generic.ArraySortHelper1.IntroSort(Span1 keys, Int32 depthLimit, Comparison`1 comparer) in System.Private.CoreLib.dll:token 0x6006a1e+0x83

at System.Collections.Generic.ArraySortHelper1.IntroSort(Span1 keys, Int32 depthLimit, Comparison`1 comparer) in System.Private.CoreLib.dll:token 0x6006a1e+0x83

at System.Collections.Generic.ArraySortHelper1.IntroSort(Span1 keys, Int32 depthLimit, Comparison`1 comparer) in System.Private.CoreLib.dll:token 0x6006a1e+0x83

at System.Collections.Generic.ArraySortHelper1.IntroSort(Span1 keys, Int32 depthLimit, Comparison`1 comparer) in System.Private.CoreLib.dll:token 0x6006a1e+0x83

at System.Collections.Generic.ArraySortHelper1.Sort(Span1 keys, IComparer`1 comparer) in System.Private.CoreLib.dll:token 0x6006a17+0x18

— End of inner exception stack trace —

at System.Collections.Generic.ArraySortHelper1.Sort(Span1 keys, IComparer`1 comparer) in System.Private.CoreLib.dll:token 0x6006a17+0x29

at System.Collections.Generic.List1.Sort(Int32 index, Int32 count, IComparer1 comparer) in System.Private.CoreLib.dll:token 0x6006bd7+0x2c

at Unity.IL2CPP.Metadata.GenericMethodCollectorComponent.SortItems(List`1 items) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/Metadata/GenericMethodCollectorComponent.cs:line 115

at Unity.IL2CPP.Contexts.Components.Base.ItemsWithMetadataIndexCollectorPhaseSortSupport`4.PhaseSortItems() in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/Contexts.Components.Base/ItemsWithMetadataIndexCollectorPhaseSortSupport.cs:line 41

at Unity.IL2CPP.AssemblyConversion.Steps.Base.ContextFreeScheduledStep`1.WorkerWrapper(Object unusedContext) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/AssemblyConversion/Steps.Base/ContextFreeScheduledStep.cs:line 21

at Unity.IL2CPP.Contexts.Scheduling.PhaseWorkScheduler`1.WorkerLoop(Object data) in /Users/bokken/build/output/unity/il2cpp/Unity.IL2CPP/Contexts.Scheduling/PhaseWorkScheduler.cs:line 287

at il2cpp.Program.DoRun(String[ ] args, RuntimePlatform platform, Il2CppCommandLineArguments il2CppCommandLineArguments, BuildingOptions buildingOptions, Boolean throwExceptions) in /Users/bokken/build/output/unity/il2cpp/il2cpp/Program.cs:line 335

UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:129)

UnityEditorInternal.Runner.RunNetCoreProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action`1[T] setupStartInfo) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/BuildUtils.cs:91)

UnityEditorInternal.IL2CPPBuilder.RunIl2CppWithArguments (System.Collections.Generic.List1[T] arguments, System.Action1[T] setupStartInfo) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:813)

UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (UnityEditor.Il2Cpp.Il2CppBuildPipelineData data) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:797)

UnityEditorInternal.IL2CPPBuilder.Run () (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:639)

UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action`1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:274)

UnityEditor.iOS.PostProcessiPhonePlayer.CrossCompileManagedDlls (UnityEditor.iOS.PostProcessiPhonePlayer+BuildSettings bs, UnityEditor.iOS.PostProcessiPhonePlayer+ProjectPaths paths, UnityEditor.AssemblyReferenceChecker checker, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport buildReport) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/BuildPostProcessor.cs:926)

UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.PostProcessiPhonePlayer+BuildSettings bs, UnityEditor.iOS.PostProcessiPhonePlayer+ProjectPaths paths, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport buildReport) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/BuildPostProcessor.cs:749)

UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.PostProcessorSettings postProcessorSettings, UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/BuildPostProcessor.cs:694)

UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/ExtensionModule.cs:45)

Rethrow as BuildFailedException: Exception of type ‘UnityEditor.Build.BuildFailedException’ was thrown.

UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at /Users/bokken/buildslave/unity/build/PlatformDependent/iPhonePlayer/Extensions/Common/ExtensionModule.cs:49)

UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at /Users/bokken/buildslave/unity/build/Editor/Mono/Modules/DefaultBuildPostprocessor.cs:28)

UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:370)

UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)

Can you submit a bug report with a project that causes this issue?

I just solved it by myself. I had a newtonsoft json package in my project. this package was not shown in the package manager I had to remove the package from the manifest and package-lock manually

Solution__________

Hello here’s the solution if you change or move the project.
Remove Il2cppBuildCache folder (Project/Library/Il2cppBuildCache)
Mostly this issue occurs when we change the project location or moved the project to another location.

1 Like