NativeScript is great. There is an easy setup process (at least for Windows, I unfortunately don’t have a Mac so I can’t speak on the MacOS side of things) that provides an executable that helps you through all the steps of setup. Unfortunately, like any automated setup process, things can go awry and stop your excitement on starting on your native apps with some errors that have little suggestion on how to move forward. This guide will help you go through the steps to install and use NativeScript manually, so whether you’re having difficulties with the simple setup, or want to customize a few things along the way, you’re ready to rock and roll.
You’ll also need to have JDK 8 installed. The download page can be found here. You’ll want to select Java SE Development Kit 8. This installer should also include the installation option to include Public Java Runtime, which is also known as JRE. This option should be left on as it is needed.
If you have a previous version of JDK installed, you may need to set a
JAVA_HOME path variable equal to the installation path of your JDK install (EG: C:\Program Files\Java\jdk1.8.0_152). More on path variable adding further into this article.
Although this SHOULDN’T be needed, I also had to add my JDK bin folder (EG: C:\Program Files\Java\jdk1.8.0_15\bin) to my path in order to stop all warnings and errors from showing up when installing NativeScript.
The next step is a bit more niche. You’re going to want do download the Android SDK. While this is packaged with Android Studio, and a simple install of that would do the job, it also takes up MUCH more space than the SDK alone. If you’re limited on storage, or simply don’t want to have Android Studio take up another slot on your program list, you can setup the command line version of the SDK by itself. Download the ZIP here.
Extract the ZIP file to a directory called Android and place it in the respective folder for your platform:
In order to use the tools in this folder from any location, you’ll need to add the Android/tools and Android/platform-tools folders to your path. This will allow you to run commands from the SDK such as
Run the command:
And add the line:
Open Explorer, and right click on This PC and select Properties
Click on Advanced system settings:
It will bring up a dialog for System Properties. In the Advanced tab, click Environment Variables.
Then, click on the Path list item in System variables. Then add
C:\Android\tools to the list.
Finally, add a new variable in System variables called
ANDROID_HOME with the value
If, after restarting any open
powershell sessions, you are still unable to run
sdkmanager, try adding
C:\Android\tools\bin to your path as well.
Open a console and run:
sdkmanager 'extras;google;m2repository' 'extras;android;m2repository' 'extras;m2repository;com;android;support;constraint;constraint-layout;1.0.2' 'extras;m2repository;com;android;support;constraint;constraint-layout-solver;1.0.2' 'emulator' 'platform-tools' 'build-tools;25.0.3' 'extras;google;google_play_services' 'extras;intel;Hardware_Accelerated_Execution_Manager' 'platforms;android-24' 'system-images;android-24;google_apis;x86_64'
This will install the needed Android repos, support libraries, build tools, and other SDK tools for Android. You may need to accept licenses. When prompted, type
y to accept.
You may get an error that you’re unable to install Intel Hardware Accelerated Execution Manager. If you encounter this error, check that you have virtualization enabled in your BIOs.
We need to make a test device to run our app on. In order to do so, run the following command
avdmanager create avd -k 'system-images;android-24;google_apis;x86_64' -d 9 -n "Nexus_5X" -b 'google_apis/x86_64'
This will create a clone of the Nexus 5X to test your app on.
Finally, to install NativeScript, run:
npm install -g nativescript
It will prompt you to run the setup script (which is what we’ve essentially already done manually), when it does so, select “No” (type
You may see suggestions (in yellow) and errors (in red) displayed when you run the install command for NativeScript. Be sure to slow down and read these if you come across any errors. Feel free to leave a comment down below if you get stuck.
Great, you have the framework installed! But now what? I don’t have a template to go off of, have little understanding of the commands I need to run to get it all going; or perhaps, you already know the steps and want to cut off the cruft to get to the goodies. Luckily for you, Progress (the parent company behind NativeScript) has an answer for you: NativeScript Sidekick.
Sidekick allows you to start new projects with a myriad of templates to chose from. You can also go ahead and do things like cloud compiling for iOS projects on a Windows box, and change basic settings for each platform (iOS and Android). What are you waiting for? You can grab your copy here and learn how to use it in a previously written The Polyglot Developer tutorial titled, NativeScript Sidekick For Assisted Project Creation And Cloud Building!