Upgrading to NativeScript v1.3 from earlier versions.

To update you need to upgrade a couple items, recommended that you do it in order.   Also, a word of caution once you upgrade your NativeScript CLI, you need to upgrade your platform and common modules for any of your other projects.   It is supposed to be backwards compatible; but I was not successful in getting the new version of TNS CLI to compile an older project properly.  Rather than spend any amount of time trying to get it to work, it was simpler just to upgrade the platform and common core modules...

Make sure you are NOT running Node v4.00; The current v4.00 version of Node does NOT work.   If you need to downgrade node, I recommend you grab the latest version of Node v0.12.x from https://nodejs.org/download/release/latest-v0.12.x/.   If you are already running node and it is working for you; you don't need to upgrade it.  This note is just to make sure you DON'T upgrade node to v4.00.

Next thing if you are doing anything with Android; you want to do is type "gradle --version" and see if it runs.  If it doesn't run from the command line you need to either install gradle or set your path to use it.   If you have Android Studio installed; gradle is including with Android Studio, so you don't have to install it again.  For example on my Windows machine; my gradle is located at: C:\Program Files (x86)\Android\android-studio\gradle\gradle-2.4\bin.   So I added that to my path, so now gradle can run from anywhere.  If you are using Ubuntu, the version included is really old and you will need to install a ppa from: https://launchpad.net/~cwchien/+archive/ubuntu/gradle Then you will be able to do a sudo apt-get update && sudo apt-get install gradle and get a much more recent version.   On a Macintosh, it is recommended you install brew, and then do a brew install gradle.   You can alternatively download and install it directly from https://gradle.org/.   You must be running at least v2.3 of Gradle.

Edit 2015/09/17: The new version of the build system uses gradle and the gradle configuration file REQURIES that you are running v22.0.1 of the Android Build tools. In the grunt based build system you could use v21 or v23.0.1. Since this has caught a few people; you will want to open up the Android SDK installer, and make sure to install Build Tools v22.0.1

The next thing you need to make sure is that you have your ANDROID_HOME and JAVA_HOME environmental variables set.   If you don't have them set you will get error messages about these needing to be set.  On Windows you can do echo %ANDROID_HOME%  %JAVA_HOME% to see if they are set.  On Macintosh and Linux you can do echo $ANDROID_HOME $JAVA_HOME to see them.

So, now that you have your environment all setup; we need to upgrade the NativeScript Command Line utility, first.  This is very important, before you even attempt to upgrade the platform modules you MUST be running the new version of the NativeScript CLI.

The easiest way is to do a: npm remove nativescript -g   Yes, we want to de-install the current version; trust me it is easier this way.  You can do a in-place update; but the times I tried it it threw errors; and I had to do it a couple times to get it installed.   So, it is much easier just to de-install it. Then you just type:  npm install nativescript  -g to re-install it.

If everything worked fine; you should be able to do: tns --version and you will see v1.3.0

The next piece you need to do is upgrade your platform.  Before you upgrade; you will want to make sure you backup any changes you made in the platform folder as both methods can overwrite the project files.  You can do it one of two ways; my way or the simpler way.   Telerik recommends the simpler way; you do a tns platform update android or tns platform update ios.    In most cases this works great.   However, in some of the past updates it has left you with a broken platform and then you still had to do it my way to fix it.    So rather than have the chance that you will get a broken platform, I of course will recommend my way.

My way is the nuclear option!  tns platform remove android and then tns platform add android.   I remove and then re-add back the platform.   Now, this will totally DELETE your platform/android or platform/ios folders.  So if you made any customization to your project files; I'm going to re-stress this -- you will want to back them up first.

The final piece is updating the common core tns-core-modules; in past versions of nativescript this was a bit of a pain to upgrade.  No more, it is now very simple!   The first thing you can do is just totally delete your app/tns_modules folder.  It is not used any more, totally ignored and now a waste of disk space.   Then you just type npm install tns-core-modules --save from inside your root project folder.    This will install the core modules in the node_modules folder like any other nativescript plugin.  So now in the future you can do a simple npm update tns-core-modules and have the latest version.

And finally after everything is all done; you can do a:
tns prepare android
tns prepare ios

And you should see it confirm everything is good to go...   Happy hacking on your NativeScript application.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.