17

I am getting this error:

"error: unable to spawn process (Argument list too long)

** ARCHIVE FAILED **

The following build commands failed: CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (1 failure)

Exitcode =65 "

I went through this link: Xcode export localization throws error "Argument list too long"

This article provides a good temporary solution of the problem stating to reduce the path hierarchy. But this does not seem to be an appropriate approach. Can anyone provide me with a different approach to the solution for this problem?

Screenshot added

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
Falguni
  • 181
  • 1
  • 1
  • 4
  • This is basically due to long path names because of which compiler is not able build . Solution is to chose ar path that has shorter name.Try renaming your project. – Jayprakash Dubey Oct 03 '19 at 11:44

12 Answers12

20

In my case, it was about custom configurations in .xcconfig files. My config files were including Pods configurations like:

// Development.xcconfig

#include "Pods/Target Support Files/Pods-MyProject/Pods-MyProject.debug (development).xcconfig"
#include "Pods/Target Support Files/Pods-MyProjectTests/Pods-MyProjectTests.debug (development).xcconfig"

#include "Pods/Target Support Files/Pods-MyProject/Pods-MyProject.release (development).xcconfig"
#include "Pods/Target Support Files/Pods-MyProjectTests/Pods-MyProjectTests.release (development).xcconfig"
// Production.xcconfig

#include "Pods/Target Support Files/Pods-MyProject/Pods-MyProject.debug (production).xcconfig"
#include "Pods/Target Support Files/Pods-MyProjectTests/Pods-MyProjectTests.debug (production).xcconfig"

#include "Pods/Target Support Files/Pods-MyProject/Pods-MyProject.release (production).xcconfig"
#include "Pods/Target Support Files/Pods-MyProjectTests/Pods-MyProjectTests.release (production).xcconfig"

This produced the error you mentioned, when I added Firebase pods into my Podfile.

So to make this compile again I had to:

  1. remove all inclusion (#include ...),
  2. set them explicitly in the Project -> Info -> Configuration, as follows:

Solution

Quick tip:

If you don't want manually setting up corresponding target configurations (those with red icon), mark them as None and run pod install. This will automatically change it for you. Quick tip

blaszku
  • 269
  • 2
  • 10
  • 2
    This fixed it for me. I'm using custom xcconfig files with Cocoapods and had this issue. – primulaveris Mar 25 '20 at 12:41
  • 2
    Thank you so much! This worked for me, I've been trying to figure out what was wrong for the longest time, I was using the legacy build system in the meantime... Definitely the answer if you're using custom xcconfig files with cocoapods – jnwagstaff May 29 '20 at 17:46
  • Okay after reading this post a bunch more times, this WORKED! Thank you!! – Mario Bouchedid Jan 27 '21 at 01:15
7

A few days ago I faced a similar challenge. I want to provide details and share my research with SO community.

First of all I found this thread and I followed the link in the asked question.
And yes, thats right, the answer marked in the link is correct, but the solutions to this problem did not suit me.

Problem

In my case, I had this problem when I changed the folder hierarchy in my project to be more convenient and suitable for me.
@oOEric option did not suit me, because according to the rules, the hierarchy of groups in Xcode should coincide with the hierarchy of folders in the system.
But I've already had about 1680 swift files to compiling.

The problem was that I had too long path to the compiled files and their number was too large.

Research

Then I start research and found swift jira with the same bug. Here some links:

  1. Main
  2. Linked Issue 1
  3. Linked Issue 2
  4. Linked Issue 3
  5. Bug on Open Radar

But here I didn't find some solutions for me.

Most of all I was pleased with this response of the swift developers.

Again, this is an Xcode-side issue, not a Swift-side issue. Commenting here won't make the Xcode engineers work any faster! (We're not all the same people at Apple.)

Okey, after this answer, I was finally convinced that if it is an Xcode bug, then the solution should be sought in Xcode.

Solutions

  1. Temporary solution

You need to move your project higher in the hierarchy of your system.

I choose this one, because I have really big project and the use of other solutions will require more than one day from me.

In my case, I conducted an experiment and calculated that the length of the path to the project should be no more than 50 characters.

But this is a temporary solution. If your project grows further, you will have to shorten the path or use other solutions.

  1. Cocoa Touch Framework target

This solution is suitable for files that do not use dependencies.

First of all you need to add Cocoa Touch Framework as a target to you main project.

enter image description here

This target should be added automatically to Embedded Binaries and Linked Framework and Libraries.

After this you need to find some files without dependencies and change target membership to your "TestTarget".

enter image description here

Don't forget classes, properties, methods, enums, protocols from cocoa touch framework should have open or public access.

And don't forget clean your DerivedData folder.

  1. Modular iOS

This solution has a more integrated approach.

If you want to use any dependencies in your Cocoa Touch Frameworks you should go to this guide and make more complex refactoring for your big project!

Link to solution

I think this is the best solution.

I hope this big answer will help someone!

Vlad Krupenko
  • 361
  • 2
  • 9
4

I solved this by setting build system to Legacy build system in file-> workspace setting -> select workspace setting

2

I solved this by reducing the hierarchy of groups in Xcode.

e.g. original files at project_name/project_name/About/Model/Text I removed the groups "Model", "Text" and moved files under project_name/project_name/About/

oOEric
  • 1,069
  • 1
  • 10
  • 25
1

I made simple script for temporary fix that problem. https://github.com/gregoryvit/flatter

It simply move all swift files in Xcode project to root group.

1

Error - unable to spawn process (Argument list too long)

There are many reason for this error. Some of these are mentioned below:

  • Your project might have many swift files (say more than 2000)
  • Most of the Swift source files may be deeply nested inside directories

Screenshot for deeply nested folder structure

  • Many of these files have absolute paths with more than 150 characters (eg. /Macintosh HD⁩/⁨Users⁩/jayprakashnd⁩/⁨mySampleProject/Module1…)

Screenshot for absolute path

Xcode swift complier takes the absolute paths of all source files while so compiling, the ARG_MX limit is reached and build fails.

This has been fixed in Xcode 11 wherein a flag is used to set unlimited number of swift files.

Solutions:

  1. Switch to Xcode 11 and add USE_SWIFT_RESPONSE_FILE to YES in build settings - User Defined Section

  2. If you cannot switch to Xcode 11 then take a new checkout of your project in Macintosh HD⁩ ▸ ⁨Users⁩ directory with folder name as minimal as possible.

Solution 2 worked for me like a charm!

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
0

It happened to me when I use Xcode 11 beta version using Live Preview. Then I solved it by restarting Xcode after that error has gone.

atalayasa
  • 3,310
  • 25
  • 42
0

I have fixed this issue, moving my folder of My Xcode project to the mac root and changing my name Folder to less characters.

  1. Terminal: cd /

  2. Change name folder to BX (example).

A. Trejo
  • 641
  • 8
  • 17
0

xcode11

-build setting

-user-defined

-add setting: USE_SWIFT_RESPONSE_FILE

-setValue: YES

Doing this you enable xcode to have more files than is allowed. But im not sure if this always solve the problem.

0

I have changed build type to legacy and it also resolved problem for me, both locally and on our CI builder. For me it was caused during checking Podfile.lock and Manifest.lock. Probably this could be skipped in our pipeline since we are always installing pods on CI.

lisek
  • 267
  • 4
  • 16
0

If you faced this issue on your Flutter project while building in Release mode (or Archive) check out my this answer: https://stackoverflow.com/a/61446892/5502121 Long story short:

  • set your build system to New Build System in File > Project Settings…
  • remove ios and build_ios folders
  • run flutter create . to init new ios module
  • run pod install
  • run flutter pub get
  • check your Xcode build config (it should be Release mode and General iOS Device)

and you're good to go

Kirill Karmazin
  • 6,256
  • 2
  • 54
  • 42
-1

I have the same problem. I fix it using a temporary solution, however that work for me.

My solution is to change the Derived Data folder to a directory with a shorter path.

The Steps is as the following:

Xcode -> File -> Workspace Settings... -> Select Custom Location for Derived Data and give a shorter path as the location.

Viton Zhang
  • 306
  • 2
  • 8