Post

Setting Up a Development Environment for macOS for Mobile Programming (Part 2)

Setting Up a Development Environment for macOS for Mobile Programming (Part 2)

Installing Xcode

What is Xcode?

Xcode is Apple’s official IDE for developing applications on iOS, macOS, watchOS, and tvOS. It includes tools for coding, debugging, version control, UI design, and testing. Xcode supports programming languages like Swift, Objective-C, and C++.

How to Install Xcode

  1. Open the App Store on your Mac.
  2. Search for Xcode.
  3. Click Install and wait for the installation to complete.

Installing CocoaPods

CocoaPods is a dependency manager for iOS and macOS projects. It simplifies adding, updating, and managing libraries.

To install CocoaPods, use one of the following commands:

1
brew install cocoapods

or

1
gem install cocoapods

Note: If using gem, consider installing rbenv or rvm to manage Ruby environments and avoid conflicts with macOS’s default Ruby.

DevCleaner for Xcode

Install DevCleaner for Xcode from the App Store to clean up cache and derived data generated by Xcode. This is especially useful for React Native projects, as the cache can grow significantly.


Rosetta and Chip Architecture Issues

What is Rosetta?

Rosetta is a macOS tool that allows applications designed for Intel architecture to run on Apple Silicon (M1/M2) Macs. While not as fast as native apps, it ensures compatibility with older software.

When to Use Rosetta?

By default, Xcode and Terminal support the latest chip architecture. However, if you’re working on older projects or dependencies (e.g., node-sass v4 or v5), you may need to enable Rosetta.

How to Enable Rosetta for Xcode

  1. Open the Applications folder.
  2. Right-click on Xcode and select Get Info.
  3. Check the box for Open using Rosetta.
  4. Restart Xcode.

Installing Java

For Android development, Java 11 is the most stable version. Avoid installing multiple Java versions unless necessary.

Azul JDK is a free, easy-to-install Java distribution. Download it from Azul’s website.

After installation, set Java 11 as the default by adding the following line to ~/.zshrc:

1
export JAVA_HOME="/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home"

Installing Android Studio

What is Android Studio?

Android Studio is Google’s official IDE for Android development. It includes tools for coding, debugging, UI design, and APK building.

How to Install Android Studio

  1. Visit Android Studio’s official website.
  2. Download the version matching your Mac’s chip architecture (Intel or Apple Silicon).
  3. Install and launch Android Studio.

Configuring the Android Environment

  1. Open Android Studio and complete the initial setup.
  2. Go to SDK Manager (accessible via the three-dot menu next to “New Project”).
  3. Configure the following:

Android Platform Tools

Select the Android versions you need (e.g., the latest version or older ones for legacy projects).

Android SDK Tools

Enable Android SDK Command Line Tools. This is mandatory for Flutter development.

Setting Environment Variables

Add the following lines to ~/.zshrc:

1
2
3
4
5
6
# Android
export ANDROID_HOME="${HOME}/Library/Android/sdk"
export PATH="${PATH}:${ANDROID_HOME}/platform-tools"
export PATH="${PATH}:${ANDROID_HOME}/cmdline-tools"
export PATH="${PATH}:${ANDROID_HOME}/tools"
export PATH="${PATH}:${ANDROID_HOME}/tools/bin"

Verify the setup by running:

1
2
which adb
which sdkmanager

Installing Flutter

Download Flutter SDK

  1. Visit Flutter’s installation page.
  2. Download the SDK for your Mac’s architecture.
  3. Extract the SDK to a directory (e.g., /opt/flutter).

Configure Flutter Environment

Add the following lines to ~/.zshrc:

1
2
3
# Flutter
export PATH="${PATH}:/opt/flutter/bin"
export PATH="${PATH}:/opt/flutter/bin/cache/dart-sdk/bin"

Install Chrome for Debugging

Flutter uses Chrome for debugging web apps. Install Google Chrome or another Chromium-based browser. If using a non-default browser (e.g., Microsoft Edge), specify its path in ~/.zshrc:

1
export CHROME_EXECUTABLE="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"

Conclusion

This guide covers essential tools and configurations for mobile development on macOS, including Xcode, Android Studio, and Flutter. By following these steps, you’ll have a robust environment ready for cross-platform development.

This post is licensed under CC BY 4.0 by the author.