NativeScript With Android Emulator on Arch Linux
Today I wanted to try out NativeScript:
NativeScript enables you to build truly native apps for iOS, Android, and the Web, from a single JavaScript code base. With support for TypeScript, CSS, and popular frameworks like Angular and Vue.js.
Install NativeScript⌗
Either use Arch’s native packager or npm
.
With the AUR:
yay -S nativescript
If you choose to install NativeScript via Node, do it like this:
npm i -g nativescript
Now you can bootstrap a NativeScript:
tns create <name-of-app>
Or you can use npx
and create a local install (my preference).
npx nativescript create <name-of-app>
Android SDK⌗
Java 8⌗
You’ll need Java 8:
yay -S jdk8-openjdk8
Select Y
to install that package and any additional packages that are needed.
Create the JAVA_HOME
environment variable:
export JAVA_HOME=/usr/lib/jvm/default
Android SDK⌗
Install Android SDK and necessary build tools:
yay -S android-sdk android-sdk-platform-tools android-sdk-build-tools android-platform
Fix User Permissions⌗
The AUR installs the Android tools into /opt/android-sdk
. The directory has root permissions, so let’s change that:
sudo groupadd android-sdk
sudo gpasswd -a <user> android-sdk
sudo setfacl -R -m g:android-sdk:rwx /opt/android-sdk
sudo setfacl -d -m g:android-sdk:rwX /opt/android-sdk
Re-login.
Don’t forget to add the environment variable to your bash profile file (.bashrc
or similar).
Set the variable ANDROID_SDK_ROOT
to /opt/android-sdk
:
export ANDROID_SDK_ROOT='/opt/android-sdk'
Android Emulator⌗
You’ll need to install the required Android image with sdkmanager
:
sdkmanager --list
Then install a system image, for example:
sdkmanager --install "system-images;android-29;default;x86"
Now you can create an emulator:
avdmanager create avd -n <name> -k "system-images;android-29;default;x86"
(Replace <name>
with the name you want to give the emulator.)
See avdmanager for more infos.
Here’s a handy cheat sheet on GitHub.
You might get errors that “there is no space lift on device”. The error indicates that your /tmp
folder is full: I am getting a no space left on device error.
Try clearing the folder or increase the available space in /tmp
(instructions in link above).
Add the emulator path to your user paths, for example, in Bash:
# Android SDK
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/platform-tools/
export PATH=$PATH:$ANDROID_HOME/tools/bin/
export PATH=$PATH:$ANDROID_HOME/tools/
PATH=$ANDROID_HOME/emulator:$PATH
(Adjust to your needs.)
For example, the error “PANIC: Missing emulator engine program for ‘x86’ CPUS.” indicates that the emulator
program is not in your path.
Run Android Emulator (Standalone)⌗
emulator @<name-of-the-generated-avd> &
The command starts the emulator in the background.
Run the Emulator via NativeScript⌗
You can also run the emulator with the NativeScript CLI.
Inside your NativeScript project directory, run the following command in the terminal:
tns run android --bundle
Choose “local setup” and NativeScript should pick up the emulator.
Or, if you didn’t install the CLI globally, run this command:
npx nativescript run android --bundle