title: Xcode: Can only Archive an Aggregate Target Once
body: <p>I'm having trouble Archiving an Aggregate Target.  My app is set up like so:</p>
  
  <ul>
  <li>MyApp.xcodeproj
  
  <ul>
  <li>App1</li>
  <li>App2</li>
  <li>App3</li>
  <li>App4</li>
  <li>App1-Enterprise</li>
  <li>App2-Enterprise</li>
  <li>App3-Enterprise</li>
  <li>App4-Enterprise</li>
  <li>BuildAllEnterprise (aggregate target to build all enterprise targets)</li>
  </ul></li>
  </ul>
  
  <p>All of the targets share the same core set of files: Launch Storyboard, AppDelegate, UIViewController subclass, Storyboard, Asset Catalog.  They all have unique info.plist files.</p>
  
  <p><a href="https://i.stack.imgur.com/0Im7p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Im7p.png" alt="xcode1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/ObVyG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ObVyG.png" alt="xcode2"></a></p>
  
  <p>Adding an aggregate target and building it works perfectly.  I can also Archive it no problem the first time.  Only after I try a second archive do I get errors when the <code>CopySwiftLibs</code> command is run:</p>
  
  
  
  <blockquote>
  <pre class="lang-none prettyprint-override"><code>*** error: Couldn't copy/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos/libswiftCore.dylib
  to
  /Users/jal/Library/Developer/Xcode/DerivedData/MyApp-enstrypfbpojoqgbavkrccebdjsi/Build/Intermediates/ArchiveIntermediates/BuildAllEnterprise/BuildProductsPath/SwiftSupport/iphoneos/libswiftCore.dylib:
  A file with the name “libswiftCore.dylib” already exists.
  </code></pre>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/18p1N.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/18p1N.jpg" alt="xcode3"></a></p>
  
  <p>It's not always the same dylib.  Sometimes it's <code>libswiftDarwin.dylib</code>, other times it's <code>libswiftUIKit.dylib</code>.  I assume this issue occurs because the Swift libraries are being copied to the Derived Data folder by one target in the aggregate, and the build script is attempting to copy duplicate libraries for subsequent targets in my aggregate.</p>
  
  <p>I've had varied success cleaning my build folder/deleting Derived Data/restarting Xcode or my Mac.  But even if I can get the target to Archive properly once, it always fails the second time.</p>
  
  <p>How can I prevent this when Archiving my Aggregate Target?</p>