Can I install Xcode on an external hard drive along with the iPhone Simulator.app?

佐手、 提交于 2020-06-24 07:53:03

问题


I want to install xcode to deploy a cross platform flutter application but I cant find enough space for Xcode is there any alternative solutions to just installing it on the internal storage


回答1:


Installing Xcode and friends to an external drive

As mentioned in the comments, if you already have Xcode installed the process is quite simple. Start by moving Xcode from the Internal HD to an External one and run the commands from step 4 & 5, and this should do the trick.

My experience is that if you don't have Xcode installed already, the process is a bit involved.

There may be simpler ways to do this, but after getting different errors for every thing I've tried, I've done it this way on a MacBook Pro 16" running macOS Catalina (10.15.2) and Xcode 11.3:

I have my external drive attached to the MacBook at all times, using a bit of Velcro as the Samsung T5 drive I use is so small and light. It's mounted at:

/Volumes/SSD

On the external drive I installed Xcode into:

/Volumes/SSD/Applications

following this procedure for installing Xcode:

  1. Download the latest 11.3 Xcode release (not the Beta) from Apple's Developer Site (This is a 7.3GB Download and you need to register for a free developer account by the way)

  2. Install the Xcode command-line tools (to the internal drive), which can be triggered by running the following command in a terminal:

    sudo xcode-select --install

    This will trigger the installation of the command-line tools and establish the
    /Library/Developer/CommandLineTools

    path and set this as the default developer tools path after installation.

  3. Now, the Xcode download comes as a .xip file that needs to be expanded / unpacked using the Archive Utility included with macOS.
    I've created a directory on the SSD:
    /Volumes/SSD/Applications
    and moved the Xcode_11_3.xip file here before extracting it by double-clicking it in the Finder.
    NOTE: It will unpack to the same folder as the .xip file, into Xcode.app but leaves the 7.3GB .xip file there as well. After unpacking, you may move the .xip file somewhere for backup or just delete it.

  4. Now change the default developer tools directory with command:
    sudo xcode-select -s /Volumes/SSD/Applications/Xcode.app/Contents/Developer
    then do another zsh -lor restart the Terminal.app.

  5. After setting the Xcode.app as the default developer tools directory, run this command, to have Xcode figure itself out:
    /usr/bin/xcrun --find xcodebuild

    This took a little while, then I got back:
    /Volumes/SSD/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild

The Simulators / Emulators

The simulators, caches and all that also takes up a considerable amount of space but lives elsewhere.
For Xcode, the simulators are normally located beneath ~/Library/Developer

You'll want to move this whole directory structure to your external drive if you're looking to maximize the available space on the local drive. You can use a regular move operation via Finder.app by first doing a regular ⌘ + C (cmd+c) to copy ~/Library/Developer then in a target location, like /Volumes/<ext_drive_name>/<some_dir_name>, I use /Volumes/SSD/Library/ you can use ⌥ + ⌘ + V (opt+cmd+v) to move the copied contents directly (might require admin password).

Just had to mention this as many don't know how to "cut and paste" files in the Finder, ending up copying first then going back to delete... :)

Now make a symlink using ln -s /Volumes/SSD/Library/Developer /Users/<your_user>/Library/ and you should be able to use and update the simulators as usual.

The Android emulators are by default located somewhere beneath ~/.android/... Use the same procedure as for the Xcode simulators to move the whole ~/.android directory to a place on your external drive and symlink as described, so you end up with something like:

.android -> /Volumes/SSD/Library/android

when you do a $ ls -la ~ in your Terminal.

Note Regarding Homebrew

If you're using Homebrew for installing packages (like many does), it seems as if Homebrew doesn't register that you have the CommandLineTools installed if you move the /Library/Developer/CommandLineTools directory and will try to compile some bottles from source.
Homebrew still apparently needs some tools found in the separate Command Line Tools package installed with sudo xcode-select --install that's missing from the regular Xcode install (I noticed this when upgrading to a new version of Python, it was still being compiled from source no matter what I tried.)

So, if you use Homebrew, you're probably better off keeping the Command Line Tools installed at the default location. Just install as described with the sudo xcode-select --install command and leave it there, it's not taking up much space anyway.

I don't know, but it seems to me that this is somehow hard-coded into Homebrew's configuration somewhere or something.

Also, remember to accept the xcodebuild licenses before using a tool that depends on it, using a command like this (with your own path):

sudo /Volumes/SSD/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -license accept


As I said, there might be simpler solutions out there, but after doing it this way I've been able to use Homebrew without errors and Xcode + tools with MacOS, iOS and Flutter frameworks.

Also, I've created an alias to the Xcode.app in /Applications to have it conveniently placed together with the other apps. (Cmd + Opt drag the Xcode.app to /Applications in Finder). Saved myself a ton of space on the internal drive this way.

In response to questions in the comments:

Can I upgrade Xcode / Simulators after using this method?

As long as you create a good old "alias" from the external drive's Xcode.app to /Applications/Xcode.app by dragging the app while holding ⌥ + ⌘, I've not had any problems updating, BUT I upgrade by downloading from the Apple Developer Site, not through macOS AppStore, as I've noticed that the AppStore doesn't accept the alias and thinks that Xcode isn't installed.



来源:https://stackoverflow.com/questions/59159232/can-i-install-xcode-on-an-external-hard-drive-along-with-the-iphone-simulator-ap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!