xcodebuild exportLocalization throws "Argument list too long"

From Xcode, I am trying to export an XLIFF file to send to our translators, via "Editor > Export for Localizations". However, this immediately throws error with the message:

The operation couldn't be completed. Argument list too long


This is indeed confusing, as I cannot find a more verbose log anywhere (I have already tried checking my Console.app). So, I spent quite a few time googling – to no avail. I couldn't find similar case like this. The error itself happens only when I am trying to export for localization. I can build and run the app just fine. Here are the details of my machine:


~ $ xcodebuild -version 
Xcode 8.3.3 Build version 8C38

~ $ xcode-select -version 
xcode-select version 2347.

~ $ echo $PATH 
/Users/david.christiandy/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/david.christiandy/arctools/arcanist/bin:/usr/local/go/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands


Please note that the error happens only when I try exporting for localization. This is also true when I run the export process via xcodebuild. However, building the app runs just fine and I believe there's no problem with my header search paths.


Attempts

  • Thought there was something wrong in the code, so I tried to run the export process (via
    xcodebuild
    command) in a CI. Somehow, it's working. For the record, I am using Bitrise CI with the same stack as my system (Xcode 8.2.x, macOS 10.12)
  • Asked colleagues to run export process on their machines, and they have the same error.
  • This leads me to think that there must be something wrong with the configuration. So I made a standalone project to confirm that the export process fails consistently. Turns out, it works just fine!


So, the hypothesis I got currently is:

  • There's probably something wrong in the code, and
  • There might be tools/software (that most of our iOS engineers installed) that might contribute to the error (since the CI completes just fine).

I don't know why the CI can run the export process just fine, and I don't know when it might suddenly stop functioning (just like our local machines).



Appreciate any help on this matter. Thank you!

Accepted Reply

“Argument list too long” sounds like

E2BIG
, which you get when you try to run a child process with a huge argument list (I believe the current limit is 256 KiB). I suspect that Export for Localizations is running some sort of command line tool to do that work (probably the
extractLocStrings
tool, which you’ll find lurking within Xcode’s app bundle) and passing it full paths to each of the files in your project. Depending on how many files you have and how long those paths are, it’s easy to run into problems like this.

One of the ‘fun’ things about bugs like this is that they are dependent on where you place your project. Things might work if the project is at the top of your home directory but fail if it’s nested deep inside a subdirectory.

That also suggests a potential workaround, namely, to move your project further up in the directory hierarchy.

Finally, you should definitely file a bug about this. I believe we’ve seen this before (r. 30703294) but your report will help reinforce that this is causing problems for developers in the field. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

“Argument list too long” sounds like

E2BIG
, which you get when you try to run a child process with a huge argument list (I believe the current limit is 256 KiB). I suspect that Export for Localizations is running some sort of command line tool to do that work (probably the
extractLocStrings
tool, which you’ll find lurking within Xcode’s app bundle) and passing it full paths to each of the files in your project. Depending on how many files you have and how long those paths are, it’s easy to run into problems like this.

One of the ‘fun’ things about bugs like this is that they are dependent on where you place your project. Things might work if the project is at the top of your home directory but fail if it’s nested deep inside a subdirectory.

That also suggests a potential workaround, namely, to move your project further up in the directory hierarchy.

Finally, you should definitely file a bug about this. I believe we’ve seen this before (r. 30703294) but your report will help reinforce that this is causing problems for developers in the field. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi eskimo, sorry for the late reply.


Thank you for your explanation! Although my project is not that far away from my home directory (around 2 levels deep), I will try decreasing the indentation. It also makes sense why it would fail on local machine but works perfectly on our build machine.


Interesting to note:

  • I tried deleting several folders (remove reference only) in Xcode project tab, and it works. Initially, I suspected that there was some invalid format within the folder that I'd just deleted – but when I tried deleting a different folder, it also works. So this made me think: maybe I have too many source files.
  • I tried exporting with Xcode 9, and the error did not occur. Although, I noticed a change on the console output, the process works just fine without changing the location of the project. Hopefully this will be addressed in the upcoming Xcode 9.