Ausgabe
Ich möchte xcode installieren, um eine plattformübergreifende Flutter-Anwendung bereitzustellen, aber ich kann nicht genügend Speicherplatz für Xcode finden. Gibt es alternative Lösungen, um es einfach im internen Speicher zu installieren
Lösung
BITTE ZUERST LESEN!
Derzeit ist diese Antwort nur für Systeme gültig, die Folgendes ausführen:
XCode <= v.11.3 mit macOS <= v.10.15.2
Wieso den? (Kurzfassung):
Mit XCode 11.3.x hat Apple ein paar (bisher) ruhende Prüfungen /usr/lib/libxcselect.dylib
aktiviert, die die Überprüfung ermöglichen, ob sich die Entwicklertools auf einer schreibgeschützten / unveränderlichen Systempartition befinden, die von SIP bewacht wird, und ausgelöst werden, wenn Sie einen xcode-select -s
Verzeichniswechsel versuchen.
Die 11.x „Big Sur“ macOS-Versionen sperrten es wegen solcher Dinge noch viel härter . Das Verschieben von systembezogenen Dateien oder sogar das Booten von externen Laufwerken funktioniert nicht, da das neue “Verschlüsselungssiegel”, Teil des neuen SSV (Signed System Volume), das Booten oder Ausführen ausgewählter Programme verweigert, wenn der Hash geändert wird (Dateien in / aus usw.).
Ich habe noch keine Möglichkeit gefunden, diese Überprüfungen zu umgehen.
Ich übernehme keine Verantwortung für kaputte Systeme, nachdem ich diese Methode verwendet habe, und wenn Sie sich entscheiden, an einer neueren Version von XCode / macOS herumzubasteln, machen Sie bitte zuerst eine vollständige Sicherung! Viel Glück!
Installieren von Xcode, Simulatoren und anderen Tools auf externem Speicher
Wie in den Kommentaren erwähnt, ist der Vorgang recht einfach, wenn Sie Xcode bereits installiert haben. Beginnen Sie damit, Xcode von der internen Festplatte auf ein externes Laufwerk zu kopieren, benennen Sie das Original um und führen Sie die Befehle aus Schritt 4 und 5 aus, und dies sollte den Zweck erfüllen. Wenn dies der Fall ist, löschen Sie das ursprüngliche (jetzt umbenannte) Verzeichnis / App-Bundle.
Meine Erfahrung ist, dass der Prozess etwas komplizierter ist, wenn Sie Xcode noch nicht haben.
Es gibt möglicherweise einfachere Möglichkeiten, dies zu tun, aber nachdem ich für alles, was ich versucht habe, unterschiedliche Fehler erhalten habe, habe ich es auf einem MacBook Pro 16 “mit
macOS Catalina (10.15.2) und Xcode 11.3 so gemacht :
Ich habe mein externes Laufwerk immer am MacBook befestigt, mit ein wenig Klettverschluss, da das Samsung T5-Laufwerk, das ich verwende, so klein und leicht ist. Es ist montiert unter:
/Volumes/SSD
Auf dem externen Laufwerk habe ich Xcode kopiert in:
/Volumes/SSD/Applications
Gehen Sie folgendermaßen vor, um Xcode zu installieren:
-
Laden Sie die neueste 11.3 Xcode-Version (nicht die Beta) von Apples Entwicklerseite herunter (Dies ist ein 7,3-GB-Download und Sie müssen sich übrigens für ein kostenloses Entwicklerkonto registrieren)
-
Installieren Sie die Xcode-Befehlszeilentools (auf dem internen Laufwerk), die durch Ausführen des folgenden Befehls in einem Terminal ausgelöst werden können:
sudo xcode-select --install
Dadurch wird die Installation der Befehlszeilentools ausgelöst und der/Library/Developer/CommandLineTools
Pfad festgelegt und als Standard-Entwicklertools festgelegt Pfad nach der Installation. -
Jetzt kommt der Xcode-Download als .xip-Datei, die mit dem in macOS enthaltenen Archive Utility erweitert / entpackt werden muss.
Ich habe bereits ein Verzeichnis auf der SSD erstellt:
/Volumes/SSD/Applications
und die Datei Xcode_11_3.xip hierher verschoben, bevor ich sie per Doppelklick im Finder entpacke.
HINWEIS:
Es wird in den gleichen Ordner wie die .xip-Datei in Xcode.app entpackt , lässt aber auch die 7,3 GB große .xip-Datei dort. Nach dem Entpacken können Sie die .xip-Datei zur Sicherung irgendwo verschieben oder einfach löschen. -
Ändern Sie nun das Standardverzeichnis der Entwicklertools mit dem Befehl:
sudo xcode-select -s /Volumes/SSD/Applications/Xcode.app/Contents/Developer
Dann tun Sie einen anderenzsh -l
oder starten Sie die Terminal.app neu. -
Nachdem Sie die Xcode.app als Standardverzeichnis für Entwicklertools festgelegt haben, führen Sie diesen Befehl aus, damit Xcode sich selbst herausfindet:
/usr/bin/xcrun --find xcodebuild
Das dauerte eine Weile, dann kam ich zurück:
/Volumes/SSD/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
Verschieben der Simulatoren / Emulatoren
Die Simulatoren, Caches und all das nimmt ebenfalls viel Platz ein, lebt aber woanders.
Für Xcode befinden sich die Simulatoren normalerweise in:
~/Library/Developer/CoreSimulator
Sie sollten diese gesamte Verzeichnisstruktur auf Ihr externes Laufwerk verschieben, wenn Sie den verfügbaren Speicherplatz auf dem lokalen Laufwerk maximieren möchten. Sie können einen regulären Verschiebevorgang über Finder.app verwenden, indem Sie zuerst ein normales ⌘ + C (cmd+c) ausführen, um ihn ~/Library/Developer/CoreSimulator
dann an den Zielort zu kopieren. Sie können ⌥ + ⌘ + V
(opt+cmd+v) verwenden, um den kopierten Inhalt direkt zu verschieben (evtl Admin-Passwort erforderlich).
ich benutze/Volumes/SSD/Library/Developer/
Ich musste das nur erwähnen, da viele nicht wissen, wie man Dateien im Finder richtig “ausschneidet und einfügt”, was dazu führt, dass sie zuerst kopiert und dann wieder gelöscht werden … 🙂
Erstellen Sie nun einen Symlink mit:
ln -s /Volumes/SSD/Library/Developer/CoreSimulator /Users/<your_user>/Library/Developer
Sie sollten die Simulatoren jetzt wie gewohnt verwenden und aktualisieren können. Die erste Ausführung kann einen Fehler auslösen, aber nachfolgende Ausführungen sollten in Ordnung sein. Manchmal kann ein Neustart auch gut sein …
Die Android-Emulatoren befinden sich standardmäßig irgendwo darunter.
~/.android/
Verwenden Sie das gleiche Verfahren wie für die Xcode-Simulatoren, um das gesamte ~/.android
Verzeichnis an einen Ort auf Ihrem externen Laufwerk zu verschieben und wie beschrieben symbolisch zu verknüpfen, sodass Sie am Ende so etwas wie Folgendes erhalten:
.android -> /Volumes/SSD/Library/android
wenn Sie eine $ ls -la ~
in Ihrem Terminal tun.
Hinweis für Homebrew-Benutzer
If you’re using Homebrew for installing packages (like many does), it seems as if Homebrew won’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 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.
IMPORTANT, 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
or in cases where the developer tools are already detected and found on an external drive, and the path has been set by XCode:
sudo xcodebuild -license accept
should do the trick.
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.
Updates regarding Xcode Versions > 11.3
As I mentioned in the top of the answer, I can’t vouch for this answer if you’re using an Xcode version higher than 11.3.
I’ve gone through all the steps using a fresh install on a new machine.
I experienced a couple of showstoppers while trying to figure this one out, and I only had limited time to spare for doing this.
The problems were a bit more involved than expected.
TODO:
✅ Disk arrived today (Tue, Sep 8)
✅ Install macOS, Xcode, Android SDK and Flutter SDK dev files
✅ Move Flutter SDK, Android SDK and Android emulator to external SSD
✅ Move iOS Simulator files to external SSD
[🛑] FAILED: Move Xcode and Platform files to external SSD
✅ Adapt Zsh environment variables / scripts to reflect the changes
It appears that those who have SIP enabled (probably most users) will get in trouble when accessing tools from within the Xcode app bundle if it’s moved outside the internal drive.
You may think that, “hey, I have my tools in /usr/bin
or somewhere else, but the problem is that these files are merely shim binaries, which use a system library to resolve a path to a Developer directory, where all the actual executable files, libraries and support files are installed.
This complicates matters further as you now no longer even know which of these files are in actual use. Just try doing:
$ otool -L /usr/bin/xcrun
# or
$ otool -L /usr/bin/xcode-select
And see what pours out… Same goes for most of the tools.
If you disassemble /usr/lib/libxcselect.dylib
(is that allowed? 👀) there’s apparently some additional checks being performed when running Xcode after version 11.3.
I went back and checked and the configuration have had these tests available for a few versions, but they haven’t been activated in previous consumer builds.
So when a directory switch is attempted as described in my original answer, the libxcselect
tool will now perform at least one (in)sanity check to ensure that Xcode and its tools are run from internal (safe) storage, which has an immutable system configuration guarded by SIP.
System Integrity Protection, so, you can’t just move or delete it.
My guess is that you’ll have to disable SIP to be able to make this work, and that is not an acceptable solution, as it opens up for lots of security and stability issues (even worse performance).
Finding a Middle Ground
Problem: How to free up space on an internal drive, by moving developer files to an external drive.
I’ve tried pretty much everything I can think of regarding the moving Xcode part, but I’ve met new roadblocks and showstoppers no matter what.
SO. I had to throw in the towel on this one, finding a compromise.
I can live with having saved approximately 50GB of space on my MacBook Pro’s internal 256GB NVMe drive.
I had no trouble moving:
~/Library/Android/*
(The whole Android SDK directory)
~/.android/*
(Caches and .avd emulator image files)
Using nothing but symbolic links, after copying the contents and deleting the originals.
This is only interesting for those who develop using the Android SDK and tools, so sadly I wasn’t able to solve this madness caused by Apple’s restrictive new policy regarding executable files in “foreign, hostile” locations.
These two directories alone saved me a fair share of space, so I guess for the time being that’s about it.
I’ve tried moving some parts of the Xcode bundle out of the app bundle with varying degree of success, but as you can see in this screenshot:
The bulk of the Xcode.app is within the “Platforms” directory, and when I start messing with those files, the build tools blows up on me, but sometimes not, so I really don’t know.
Die Simulatordateien selbst können verschoben werden, und dies spart Ihnen alles zwischen einigen Gigabyte und vielen GB, je nachdem, wie viele Plattformversionen (iOS / iPadOS usw.) Sie verwenden.
Diese befinden sich im Inneren:
~/Library/Developer/CoreSimulator
Ich konnte dieses gesamte CoreSimulator-Verzeichnis ohne allzu große Probleme mithilfe von Symlinks verschieben, wie in der ursprünglichen Antwort erläutert.
Ich werde weiterhin versuchen, dies herauszufinden, aber im Moment ist es so weit.
Beantwortet von – C. Sederqvist
Antwort geprüft von – Gilberto Lyons (FixError Admin)