Skip to content

Instantly share code, notes, and snippets.

@shirakaba
Last active May 10, 2021 21:04
Show Gist options
  • Save shirakaba/87aabee6e2ec70e298e3d7c42f701675 to your computer and use it in GitHub Desktop.
Save shirakaba/87aabee6e2ec70e298e3d7c42f701675 to your computer and use it in GitHub Desktop.
Running NativeScript on Apple Silicon via Rosetta (x86 emulation)

This guide will show you how to provision an Apple Silicon machine to run a NativeScript app via Rosetta (x86 emulation). It may soon become possible to run it natively, but I believe that's pending this PR, so I had to go with Rosetta for the time being.

I did this setup on a borrowed M1 Mac Mini, so a few things had been provisioned already, but I'll do my best to retrace setup steps below.

I referenced the iOS-related setup steps in the NativeScript Advanced Setup: macOS docs. They're still up-to-date, except for referring to an older version of Node.js. Specifically, what I did was:

1) Install Homebrew:

x86 Homebrew was provisioned already on the machine, like so:

arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 

2) No need to install Ruby

I just used Apple's stock Ruby (2.6.3p62, which is only for x86).

3) Install Node for x86

Sidenote: I did experimentally try to run my NativeScript app using Node for arm64, but things ultimately failed once I reached the tns run ios command, as it produced the error Error: spawn /usr/local/lib/node_modules/nativescript/node_modules/ios-device-lib/bin/darwin/arm64/ios-device-lib ENOENT. This may shortly be solved once this PR lands, however.

arch -x86_64 brew update
arch -x86_64 brew install node@15

I also updated my .zshenv with the following path to ensure that node was on my path:

export PATH=/usr/local/bin:/bin:/sbin:/usr/bin:/usr/local/sbin:$PATH

4) Install Xcode

I just downloaded and installed it via the App Store app.

I then opened it, and accepted when it prompted me whether I'd like to install additional tools.

Next, I entered Preferences -> Locations -> Command Line Tools and selected "Xcode 12.3 (12C33)" (the only option available).

I also took this moment to log into my Xcode developer account in Preferences.

5) Install the remaining dependencies

Nothing special needed for these steps.

sudo gem install xcodeproj
sudo gem install cocoapods
pod setup
sudo easy_install pip
pip install six

6) Configure the Terminal app to open in Rosetta mode

This step is necessary for the Cocoapods installation step to work, as the native Terminal encounters an issue with the ffi gem otherwise, as documented in this GitHub issue.

See this GitHub Issue comment to show how to open Terminal in Rosetta mode.

7) Build the app

Now you must reopen the Terminal app (if you haven't already) to ensure that it's in Rosetta (x86) mode. It's needed for the ns run ios step to successfully perform the Pod install step.

ns create --react mycoolapp
cd mycoolapp
ns run ios

Your iOS app should now run in the simulator!

@shirakaba
Copy link
Author

@anarnoli

To be clear, I did all of these steps when running the terminal in native (normal) mode:

sudo gem install xcodeproj
sudo gem install cocoapods
pod setup
sudo easy_install pip
pip install six

And I did these steps when running the terminal in Rosetta mode:

ns create --react mycoolapp
cd mycoolapp
ns run ios

My instructions detail only how to run NativeScript apps in Rosetta mode, whereas the NativeScript additional notes for M1 based machines (which were written later, once M1 support was fully implemented) concern how to run NativeScript apps natively in M1 mode. It may not be possible to mix our two sets of instructions successfully.

@anarnoli
Copy link

Thanks @shirakaba.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment