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:
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)"
I just used Apple's stock Ruby (2.6.3p62
, which is only 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
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.
Nothing special needed for these steps.
sudo gem install xcodeproj
sudo gem install cocoapods
pod setup
sudo easy_install pip
pip install six
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.
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!
@andresilva-cc It should be fine for Homebrew to be installed natively as long as you have a way to install both x86 and ARM editions of Node, and to ensure that the x86 edition is the one on your path when running in Rosetta mode.
I believe you then need to run your terminal in Rosetta mode, mainly so that it runs Node in x86 mode, which in turn runs NativeScript CLI in x86 mode, and thus selects the x86
ios-device-lib
(because the ARM equivalent isn’t available yet – or at least wasn’t at the time of writing). At least that’s my understanding.