Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick fix to all your Xcode SDK issues. When you update Xcode, just run this script and all is well.
#!/usr/bin/env ruby
# fix-xcode
# Mark Rickert <mjar81@gmail.com>
# Symlinks all your old SDKs to Xcode.app every time it is updated.
# Create a directory called /SDKs and run this script.
#
# Each time you upgrade Xcode, run fix-xcode.
require 'FileUtils'
def main
# Find all the SDKs in Xcode.app that aren't symlinks.
Dir.glob("#{xcode_path}/Platforms/*.platform/Developer/SDKs/*.sdk") do |sdk|
basename = sdk.split('/').last
if File.symlink?(sdk)
puts "#{basename} is already symlinked... skipping.\n"
next
end
puts "Processing: #{basename}\n"
# Remove the old version if it exists
destination = "#{sdk_path}/#{basename}"
if File.directory?(destination)
puts " - Removing existing SDK: #{destination}.\n"
FileUtils.rm_rf destination
end
puts " - Moving the Xcode version into place in #{sdk_path}.\n"
FileUtils.mv sdk, sdk_path
end
Dir.glob("#{sdk_path}/*.sdk") do |sdk|
sdk_name = sdk.split("/").last
sdk_platform = sdk_name.match(/[a-zA-Z]{3,}/)[0]
ln_dest = "#{xcode_path}/Platforms/#{sdk_platform}.platform/Developer/SDKs/#{sdk_name}"
puts " - Symlinking #{sdk_platform}.\n"
FileUtils.ln_sf sdk, ln_dest
end
puts "\nDone! Your SDKs now live in #{sdk_path} and are symlinked properly into the Xcode.app.\n\n"
end
def xcode_path
`xcode-select --print-path`.chomp
end
def sdk_path
"/SDKs"
end
def remove_sdk version
# Remove the iOS SDK from xcode.
version = version.to_s << ".0" if version.to_s.length == 1
puts "-" * 29
puts "Removing the iOS #{version} SDK from the Xcode Bundle."
puts "-" * 29
removing = "#{xcode_path}/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS#{version}.sdk"
if File.exist? removing
FileUtils.rm_rf removing
puts "SDK successfully removed. Please restart Xcode."
else
puts "Couldn't find that SDK at path: #{removing}"
end
end
if ARGV.count == 2
if ARGV[0] == "remove"
abort "Please pass another parameter specifying what SDK to remove." unless ARGV[1]
remove_sdk "#{ARGV[1]}"
end
else
puts "-" * 29
puts "Running Fixing Xcode.app SDK Paths."
puts "-" * 29
main
end
@khaledannajar

This comment has been minimized.

Copy link

commented Nov 4, 2018

Thanks this saved my day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.