Binary rejected because invalid symlink

Hi,


I'm not sure if this is the right place to ask this, so I'm sorry if I'm using the wrong section. We're having troubles submitting our app to iTunes Connect, the email we got says:


Invalid Symlink - Your package contains a symbolic link 'PlugIns/$REDACTED_WATCHKIT_EXTENSION_TARGET_NAME$.appex/$REDACTED_WATCHKIT_EXTENSION_TARGET_NAME$.appex' which resolves to a location '/Users/$REDACTED_USER$/Library/Developer/Xcode/DerivedData/Seta-ctfzptralingvtbxhssdlkkzkclw/Build/Intermediates/ArchiveIntermediates/Seta/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/$REDACTED_WATCHKIT_EXTENSION_TARGET_NAME$.appex' that does not exist or is outside of the package.


I tried to reproduce the error by creating a blank Xcode project with the same settings as our project, but I couldn't get the same error from iTunes Connect. Does anyone have any idea why that symlink is being created? I checked the blank's project .ipa and it doesn't contain that symlink in that path, so that's obviosly wrong but I can't find the build setting/configuration that is creating the symlink.


I checked the xcodebuild output and I found this:


SymLink build/SetaWatchKitExtension.appex /Users/$REDACTED_USER$/Library/Developer/Xcode/DerivedData/Seta-ctfzptralingvtbxhssdlkkzkclw/Build/Intermediates/ArchiveIntermediates/Seta/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/SetaWatchKitExtension.appex

cd $REDACTED_PROJECT_PATH$

export PATH="/Applications/Xcode-7.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode-7.1.app/Contents/Developer/usr/bin:$REDACTED_PATH_ENV_VARIABLE$"

/bin/ln -sfh /Users/$REDACTED_USER$/Library/Developer/Xcode/DerivedData/Seta-ctfzptralingvtbxhssdlkkzkclw/Build/Intermediates/ArchiveIntermediates/Seta/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/$REDACTED_WATCHKIT_EXTENSION_TARGET_NAME$.appex /Users/$REDACTED_USER$/Documents/$REDACTED_PATH$/build/$REDACTED_WATCHKIT_EXTENSION_TARGET_NAME$.appex


Which seems to be fine, but somehow that symlink ends up inside the .ipa which is wrong. This occurs after Create product structure and before CompileSwiftSources during the watchkit extension build target step.


Any hints or help is greatly appreciated. I'm using Xcode 7.1.

Accepted Reply

We had to use a DTS ticket and we received the following response from Apple:


Thank you for contacting Apple Developer Technical Support (DTS). The issue seems to happen when you pass CONFIGURATION_BUILD_DIR=$PWD/build to the xcodebuild command. Instead, try removing CONFIGURATION_BUILD_DIR from the xcodebuild command, and instead, change your build location in your Workspace settings. Follow these steps:


1. In the xcodebuild command, remove CONFIGURATION_BUILD_DIR=$PWD/build 
2. Open your Workspace in Xcode 
3. Select File > Workspace Settings 
4. Click the Advanced button 
5. Select Custom > Relative to Workspace 
6. Click the Done buttons 

This will cause the build products to still go in your build directory, and the symlink in the WatchKit Extension is no longer created.


That works, the sad thing is that this settings can't be applied by command line tools, Xcode is creating a file on the following path:


Project.workspace/xcuserdata/$USER.xcuserdatad/WorkspaceSettings.xcsettings


And obviously, you don't want to add that path to your VCS, so I created a small ruby script for our CI to add the right settings and avoid this:


settingsFilePath = "#{ENV["PWD"]}/Project.xcworkspace/xcuserdata/#{ENV["USER"]}.xcuserdatad" 
FileUtils.mkpath(settingsFilePath) 
settings = {'BuildLocationStyle' => 'CustomLocation', 'CustomBuildIntermediatesPath' => 'Build/Intermediates', 'CustomBuildLocationType' => 'RelativeToWorkspace', 'CustomBuildProductsPath' => 'Build/Products'} 
File.open("#{settingsFilePath}/WorkspaceSettings.xcsettings", 'w') { |file| file.write(settings.to_plist) }

Replies

We had to use a DTS ticket and we received the following response from Apple:


Thank you for contacting Apple Developer Technical Support (DTS). The issue seems to happen when you pass CONFIGURATION_BUILD_DIR=$PWD/build to the xcodebuild command. Instead, try removing CONFIGURATION_BUILD_DIR from the xcodebuild command, and instead, change your build location in your Workspace settings. Follow these steps:


1. In the xcodebuild command, remove CONFIGURATION_BUILD_DIR=$PWD/build 
2. Open your Workspace in Xcode 
3. Select File > Workspace Settings 
4. Click the Advanced button 
5. Select Custom > Relative to Workspace 
6. Click the Done buttons 

This will cause the build products to still go in your build directory, and the symlink in the WatchKit Extension is no longer created.


That works, the sad thing is that this settings can't be applied by command line tools, Xcode is creating a file on the following path:


Project.workspace/xcuserdata/$USER.xcuserdatad/WorkspaceSettings.xcsettings


And obviously, you don't want to add that path to your VCS, so I created a small ruby script for our CI to add the right settings and avoid this:


settingsFilePath = "#{ENV["PWD"]}/Project.xcworkspace/xcuserdata/#{ENV["USER"]}.xcuserdatad" 
FileUtils.mkpath(settingsFilePath) 
settings = {'BuildLocationStyle' => 'CustomLocation', 'CustomBuildIntermediatesPath' => 'Build/Intermediates', 'CustomBuildLocationType' => 'RelativeToWorkspace', 'CustomBuildProductsPath' => 'Build/Products'} 
File.open("#{settingsFilePath}/WorkspaceSettings.xcsettings", 'w') { |file| file.write(settings.to_plist) }