Install Xcode Command Line Tools From Terminal

  

To update the CLT, go to app developer website and download the command line tool.dmg. If you have never installed Xcode before, you may be able to update with your Terminal by typing in xcode-select -install instead of visiting the developer website.

As I mentioned in the previous post, I am going to use Cocos2d-x for my game engine. I will install it and make sure it works under different operating systems (macOS, Windows, Linux) and also compiles for different platforms (minus the Android).

In this post I will go through the steps I took to install it on my Macbook Pro!

Install Xcode

First, install Xcode, the native IDE for programming for macOS and iOS.

Install Xcode Command Line Tools From Terminal
  1. Click “Install” to download and install Xcode Command Line Tools. You don’t need to 'Get Xcode' from the App Store. If you have a slow Internet connection, it may take many minutes.
  2. Mar 07, 2018 A quick side note; Homebrew is not the only way to install command line software, you can install command line tools on a Mac yourself and then compile and make software independently. For example, we discuss installing wget on Mac OS without Homebrew here and it uses the typical configure and make process.
  • Download and install Xcode from the App Store. It is the Apple’s free programming IDE and compiler.
  • Now in a new terminal install the Xcode command line tools. The command line tools are not directly necessary to make and compile a Cocos2d-x projects, but it will come handy later in different occasions which you will see later.

Install Xcode Command Line Tools From Terminal

At this point you can already compile for iOS devices. However to be able to compile for Android devices, You need to install some extra Android related stuff. It includes Apache Ant and Android Studio (and the packages that come with it: Android SDK and Android NDK).

Install Cocos2d-x 4.0

Now that Xcode is installed, it is time to install Cocos2d-x itself:

  • Installing Cocos2d-x needs Python 2.7x installed which comes natively on macOS. Check your python version in terminal to see if you have the right version. Mine is 2.7.16.
  • Download Cocos2d-x (cocos2d-x-4.0.zip) from www.cocos2d-x.org and unzip it in a folder that you want it to reside e.g. /Applications/Dev/
  • Setup Cocos2d-x by running the setup.py in a terminal from inside of the unzipped folder e.g. /Applications/Dev/cocos2d-x-4.0/
  • It sets up some environment variables first as below and then asks for some paths.
    • COCOS_CONSOLE_ROOT
    • COCOS_X_ROOT
    • COCOS_TEMPLATES_ROOT
  • If you have Android Studio and Apache Ant installed in your system (in my case they are installed in Dev folder):
    • For NDK_ROOT question, put /Users/rezagn/Library/Android/sdk/ndk-bundle
    • For ANDROID_SDK_ROOT question, put /Users/rezagn/Library/Android/sdk
    • For ANT_ROOT question, put /Applications/Dev/apache-ant-1.10.7/bin

After going through the steps I mentioned above, I have these lines added to my ~/.profile settings file:

If you don’t have these lines, add them to your setup file manually. Remember to replace my username “rezagn” with yours and make sure the paths are correct.

Create a new Cocos2d-x project

To make new projects, we will use the cocos command in the terminal. If you just type cocos and press Enter, you will get the command line options help.

Create a new project by typing the full command as bellow. Feel free to change the folder as you wish.

This will make a project called “install_test” with all the necessary files and sub folders of the Cocos2d-x project in your specified folder!

Since the new release of Cocos2d-x v4.0, CMake is used to create projects and compile under different platforms. That means that the Cocos2d-x projects won’t come with an Xcode project file like in the earlier versions. We need to make two different Xcode project files for our newly built Cocos2d-x project which we called “install_test”. One for macOS and one for iOS.

To create an Xcode project for macOS, run these commands in Terminal from inside the “install_test” project folder.

To create an Xcode project for iOS, run these commands in Terminal from inside the “install_test” project folder.

Version 3.17.2 already comes with an XCode project inside proj.ios_mac that lets you compile for both iOS and macOS.commands.
NOTE: If you don’t have cmake in terminal, try to install it with brew “brew install cmake” or “brew upgrade cmake”.

Install Xcode Command Line Tools Big Sur Terminal

Compile and run for iOS

  • Run Xcode.
  • In Xcode open the project file from “ios-build” folder of the project.
  • Select an iOS device from the top left. e.g. iPhone 11 Pro Max.
  • From the menu go to Product->Run.
  • Xcode should build the project with no problems and run it in a simulator window.

Compile and run for macOS

Considering that compiling and running for iOS needs the simulator, it might be easier and faster to do your test and development for macOS instead. To compile for macOS:

  • Run Xcode.
  • In Xcode open the project file from “proj.ios_mac” folder of the newly created test project.
  • Select “test-desktop.app” and “My Mac” as target project and device.
  • From menu go to Build->Run the same as you did for iOS and this should run the game.

Setup Xcode for fastlane

Xcode command line tools (macOS)

Installing fastlane

fastlane can be installed multiple ways. The preferred method is with Bundler. fastlane can also be installed directly through with Homebrew (if on macOS). It is possible to use macOS's system Ruby but it's not recommended as it can be hard to manage dependencies and cause conflicts.

Managed Ruby environment + Bundler (macOS/Linux/Windows)

Ruby

If you use macOS, system Ruby is not recommended. There is a variety of ways to install Ruby without having to modify your system environment. For macOS and Linux, rbenv is one of the most popular ways to manage your Ruby environment.

fastlane supports Ruby versions 2.5 or newer. Verify which Ruby version you're using:

Bundler

It is recommended that you use Bundler and Gemfile to define your dependency on fastlane. This will clearly define the fastlane version to be used and its dependencies, and will also speed up fastlane execution.

  • Install Bundler by running gem install bundler
  • Create a ./Gemfile in the root directory of your project with the content
Tools
  • Run bundle update and add both the ./Gemfile and the ./Gemfile.lock to version control
  • Every time you run fastlane, use bundle exec fastlane [lane]
  • On your CI, add bundle install as your first build step
  • To update fastlane, just run bundle update fastlane
Install xcode command line tools from terminal 8

Homebrew (macOS)

This way you don't have to install Ruby separately and instead homebrew installs the most adequate Ruby version for fastlane.See this page for details.

System Ruby + RubyGems (macOS/Linux/Windows)

This is not recommended for your local environment, but you can still install fastlane to system Ruby's environment. Using sudo often occurs unwanted results later due to file permission and makes managing your environment harder.

Setting up fastlane

Navigate your terminal to your project's directory and run

Note that if you want to create your first app on your App Store Connect account, you need to set the developer name (company_name) with PRODUCE_COMPANY_NAME environment variable:

To get more information check company_name description in the Create app documentation.

To have your Fastfile configuration written in Swift (Beta)

Swift setup is still in beta. See Fastlane.swift docs for more information.

Depending on what kind of setup you choose, different files will be set up for you. If you chose to download the existing app metadata, you'll end up with new folders that look like this:

The most interesting file is fastlane/Fastfile, which contains all the information that is needed to distribute your app.

What's next?

fastlane created all the required files for you. Now you can go ahead and customise fastlane to generate screenshots, or automatically distribute new builds, and much, much more. Here're some examples:

  • Discover all fastlane actions

Do note that if the automation you're building requires connectivity with Apple's servers, such as for code signing when building your app, or uploading your app to the App Store Connect, and so on, you will need to authenticate. Check out Authenticating with Apple services to learn the best ways to authenticate, catered for your specific use case.

Set up environment variables

fastlane requires some environment variables set up to run correctly. In particular, having your locale not set to a UTF-8 locale will cause issues with building and uploading your build. In your shell profile add the following lines:

You can find your shell profile at ~/.bashrc, ~/.bash_profile, ~/.profile or ~/.zshrc depending on your system.

Use a Gemfile

Install Xcode Command Line Tools From Terminal 7

It is recommended that you use a Gemfile to define your dependency on fastlane. This will clearly define the used fastlane version, and its dependencies, and will also speed up using fastlane.

  • Create a ./Gemfile in the root directory of your project with the content

Install Xcode Command Line Tools Terminal Catalina

  • Run [sudo] bundle update and add both the ./Gemfile and the ./Gemfile.lock to version control
  • Every time you run fastlane, use bundle exec fastlane [lane]
  • On your CI, add [sudo] bundle install as your first build step
  • To update fastlane, just run [sudo] bundle update fastlane