筆記:清除 Xcode 所佔用硬碟空間

2021111722:30

~/Library/Developer/XCTestDevices


~/Library/Developer/CoreSimulator/Devices
存放所有曾經開過的模擬器(各種版本的模擬器),都會在這裡開一個專用的 Folder 存放
可以全部刪除

目錄裡頭像這樣:
$ ls -1 ~/Library/Developer/CoreSimulator/Devices
002FF2F2-AF6F-46CE-8A5D-EB7200401118
00493DA7-441C-459F-8AB1-71483F27EEC5
01095431-499E-4AED-A6F2-183A751DED06
061C60FC-6719-4349-9604-51D0D8237934
:: :    :: :
0622FDF0-3BC6-48D3-BB54-CCEA89276BB8
06258945-9103-4684-BB5A-C39B8AC14146
066F7D71-9B95-4ECA-BD54-2585FC3AF028
device_set.plist

這個目錄下,我居然有  336 子目錄,全部刪掉後,還原 30+GB 空間

刪除的步驟:
1.關閉 Xcode 以及所有模擬器
2.兩個命令
rm -rf ~/Library/Developer/CoreSimulator/Devices

killall -9 com.apple.CoreSimulator.CoreSimulatorService   
注意,要執行這個命令
不然 Xcode 無法啟動新的模擬器



device_set.plist 是個 xml 檔案
長得像這樣:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>DefaultDevices</key>
        <dict>
                <key>com.apple.CoreSimulator.SimRuntime.iOS-10-0</key>
                <dict>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad-Air</key>
                        <string>ABA08DA2-567F-4A29-BF7B-B04966BBB957</string>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad-Air-2</key>
                        <string>5E91E713-DB90-4A6D-9B84-05E578D16FCA</string>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad-Pro</key>
                        <string>71C38F48-1D0E-4970-ADB6-932B94D2B71F</string>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad-Pro--9-7-inch-</key>
:::                       
:::                       
                </dict>
                <key>com.apple.CoreSimulator.SimRuntime.iOS-10-3</key>
                <dict>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad--5th-generation-</key>
                        <string>DAEC8406-2C62-4571-A9E4-F7DA58777043</string>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad-Air</key>
                        <string>E9E8831E-2FB4-4B2E-9F2F-D1FFD4445652</string>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad-Air-2</key>
                        <string>4983F535-6EAD-457B-B0F6-B983A4BCB9B7</string>
                        <key>com.apple.CoreSimulator.SimDeviceType.iPad-Pro</key>
:::                       :::                       
                    
                </dict>
:: ::
:: ::


~/Library/Developer/Xcode/DerivedData
這裡存放所有 build 過的 app 的檔案
當寫越多 app 或常常下載別人的 source code 測試
會在這個目錄佔用大量空間
隨時刪除 無所謂..


/Applications/Xcode.app/Contents/Developer/Platforms
各平台的 SDK 目錄,用不到的就刪除
例如 AppleTVOS.platform  (佔了2GB)
 
$ ls -1 /Applications/Xcode.app/Contents/Developer/Platforms
AppleTVOS.platform
AppleTVSimulator.platform
MacOSX.platform
WatchOS.platform
WatchSimulator.platform
iPhoneOS.platform
iPhoneSimulator.platform


/Library/Developer/CoreSimulator/Profiles/Runtimes
Simulator runtime
一個版本 約佔 4~5GB
$ ls -1 /Library/Developer/CoreSimulator/Profiles/Runtimes
iOS 10.0.simruntime
iOS 10.3.simruntime
iOS 12.2.simruntime
iOS 13.1.simruntime


~/Library/Developer/Xcode/iOS DeviceSupport
Mac 電腦連接過的 iOS 設備( iPhone/iPad...),就會在這裡產生一個 folder ,
一個 folder 可能占用多達 2+GB
可以隨時刪除

$ ls -l ~Library/Developer/Xcode/iOS\ DeviceSupport
total 0
drwxr-xr-x  5 fire  staff  160  1 12 16:02 14.2 (18B92) arm64e
drwxr-xr-x  5 fire  staff  160  1 12 16:45 14.3 (18C66) arm64e
drwxr-xr-x  5 fire  staff  160  1 28 14:37 14.4 (18D52) arm64e
**佔用 12GB




2024/2/5
這裡有個 sh 的清垃圾 script
https://github.com/mac-cleanup/mac-cleanup-sh

  同時也有 python 版本 (會有進度條的動畫效果)
  https://github.com/mac-cleanup/mac-cleanup-py



 


  •   asd9595 於 2019-11-27 06:48 1F
  • 感恩您的分享,很實用的知識,南無阿彌陀佛,闔家平安吉祥。
  • 版主於 2019-11-27 06:56 回覆
    早安~