React Native

Cleaning disk space on your Mac

I have been developing React-Native apps for more than one year now. Since Apple machines are quite expensive, I've only picked 256 GB Mac Book Pro for developing and sadly, it has been filled faster than I expected. A lot of space were taken by XCode but it can be tricky for a React Native developer to know what you can delete safely. In this blog post, I'm going to share what I did to remove more than 30 GB of "useless" files from iOS builds.

Before cleaninng:

 

Disk space before

 

After cleaning:

 

Disk space after

 

Before starting, be sure that all the apps you have developed have their code under a version control system. We are going to delete a lot of cached data, and you probably want to not lose all your work ?

A useful bash command

Before digging into the actions I've taken, there is one command you MUST know when you want to find what files and folders are taking spaces on your machine:

++pre>++code>$ find . -maxdepth 1 -mindepth 1 -type d -exec du -hs {} + | sort -r -h
++/code>++/pre>

The find utility recursively descends the directory tree for each path listed. In our case we tell it to get the size of each directory present in the current path (++code>-maxdepth 1 -mindepth 1++/code>) only, and to sort it by size ( ++code>sort -r -h++/code>).

At the end, this bash command will list the files with their sizes associated sorted from the biggest one to the smallest one in the current directory. Really useful to know by yourself what files/folders taking the more spaces on your computer.

I recommand you to use this command wherever you can if you want to investigate by yourself what directory takes the more space in your computer. Most of the next chapters come from analysis of data that I got from it.

Cleaning Archives and Derived Data

One thing we will do first is cleaning our code that is cached when we build our iOS apps. I invite you to download that awesome CLI tool that is also useful for your day-to-day react-native work when you have issue with your cache: rn-game-over

From your terminal, install it, and then run the command to clean your iOS cache:

++pre>++code>npm install -g rn-game-over
rn-game-over -o
++/code>++/pre>

It will basically clean your derived data and Archives that have been stored during the iOS builds. As for myself, this allowed me to free a couple of Gigabytes from my disk.

Deleting unused simulators

It is interesting to notice that every time you create and launch a new simulator in XCode, more than 500 Mb are allocated to it. And after quite some time of development, the list of simulators you have available in XCode can be really large which means a lot of disk space is reserved for your simulators.

My advice: Delete all simulators and recreate the ones that you use the most.

You can easily add them again if you need it. For instance, I personally use a lot the iPhone 11 Pro Max and the iPhone SE during my developments. So I've recreated both of them only.

1. Open XCode

2. Window -> Devices and Simulators

3. One by one select them and press the Delete key in your keyboard to delete them.


 

Simulator list

4. Then clear all the data of the builds you made in it:

++pre>++code>$ cd ~/Library/Developer/CoreSimulator/Devices
$ rm -rf *++/code>++/pre>

5. Now you can create new ones that you really use that will be virgin of any apps (so no extra space taken).

Deleting outdated versions of iOS

Now that you have cleaned up your simulator, we can also remove from XCode, versions of iOS that you won't use anymore because they are not used by your users. They can be still downloaded again if needed.

++pre>++code>$ cd ~/Library/Developer/Xcode/iOS DeviceSupport
++/code>++/pre>

There, you can delete iOS versions that you consider you won't be using much. Versions that are not the ones that your simulators use or versions not really used according to this website about iOS versions market share. For deleting, just do:

++pre>++code>$ rm -rf <ios_version_folder>
++/code>++/pre>

To give you an example, I had personally had those many versions. And I only kept iOS 10.3.3 and iOS 13.2.3 in order to save as much disk space as possible:

 

iOS versions

 

Conclusion

As shown above, it has allowed me to gain 30 GB of disk space in my MacBook. I felt really happy as a react-native developer to clean safely stuff from XCode and iOS builds.

You can also read this post in Pierres's blog

Développeur mobile ?

Rejoins nos équipes