Skip to main content

Installing Cordova on Ubuntu 16.04 without Android Studio

Apache Cordova is a platform to build mobile applications using JavaScript, HTML5 and CSS.

When I was trying to install cordova for creating an android application on my Ubuntu 16.04 I was facing lot of versioning and dependency problems. So in this post I will be discussing about all those issues and the solution that worked for me. All the steps are via command line and so no android studio. I don't want to install GB's of files to just use sdk.
Steps:
  • Install latest version of node and npm
  • Install Cordova
  • Install android SDK (Command line)
  • Setting environment variables
  • Creating android plaform
  • Creating and running first app
Installing latest version of nodejs
By default ubuntu 16.04 has a stable version of nodejs added in its own repository. So to install latest version from Ubuntu itself you can simply use apt commad as follows.
$ sudo apt update
$ sudo apt install nodejs
But when I was using this version (4.2.6 is the latest stable version available when I was trying) I got some dependency error while trying to install Cordova. So I forced to add 3rd party ppa to get the latest version of nodejs. But the problem is I had some other project which uses this version of nodejs which is really mandatory.
I found a solution for this by using NVM (Node Version Manager). Using nvm you can install as many version of nodejs you want and switch it from version to version conveniently.
Installing nvm on ubuntu 16.04
$ sudo apt install build-essential libssl-dev
$ sudo apt install curl
$ sudo apt install git
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh | bash
Note: In the above url v0.31.0 is the nvm version and this is the latest version available when I was installing.
Close and open the terminal to use nvm (to refresh env) and check the nvm version using following command
$ nvm --version
To install any version of nodejs
$ nvm install 8.1
The above command will install latest build available under nodejs version 8.1. To install the latest version of nodejs available in the repository
$ nvm install node
To list all the installed nodejs versions
$ nvm ls
To use a version
$ nvm use 4.6
Note: 4.6 is the version number
Done, Now you have installed Nodejs!
Installing Cordova
To install cordova you can simply use the npm command and rest all will be taken care.
$ npm install cordova
Don't use sudo when you are using nodejs via nvm, if the installation fails and requires permission. There is a hack to make your current nodejs available for root using following command
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
Note: The above command is copying the current version, so at any time in future you switched to another version and that requires sudo, re-run the above command again.
Good! Now you have successfully installed cordova.
Installing android SDK
Downloading sdkmanager:
Goto https://developer.android.com/studio/index.html and scroll down to see "Get Just command line tools" portion and select the sdk download link for linux. Once downloaded extract it to your home directory.
Installing Java if not installed before
$ sudo apt update
$ sudo apt install default-jre
$ sudo apt install default-jdk
Updating sdk with required platform-tools
$ cd /home/<user-name>/sdk/tools
$ ./android update sdk --no-ui
Wait for update to finish, you will see "Done!" message once update is completed. Refer this documentation for how to use command line sdk-manager https://developer.android.com/studio/command-line/sdkmanager.html
Install gradle and adb
$ sudo apt install gradle
$ sudo apt install adb
Setting up cordova environment for Android application
$ cd
$ vi .bashrc
and add the following environment variables at the end of the file
# Cordova setup
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/;
export PATH=$PATH:"/home/<user-name>/sdk/platform-tools/";
export PATH=$PATH:"/home/<user-name>/sdk/tools/";
export PATH=$PATH:"/home/<user-name>/sdk/tools/bin/";
Note: <user-name> should be replaced with your Ubuntu user-name. And I am assuming you extracted that sdk zip file to your home directory with name sdk.
Your installed version of java might be different and so make sure you are setting the correct path for JAVA_HOME.
Even after giving correct path for JAVA_HOME I had an issue saying Java path is missing. Basically your java and javac command should point to the same version. You can use following command to choose the required default javac.
$ sudo update-alternatives --config javac
Configuring sdkmanager with dependency:
Install the target android platform
sdkmanager "platforms;android-26"
Creating and testing your first Cordova app
$ cordova create hello com.example.hello HelloWorld
$ cd hello
$ cordova add platform android
Connect your android device ( I am assuming you have respective driver installed and adb was able to detect your device)
Test your first app
$ cordova run android
If you see the app installed and opened in your mobile. Congrats! you have successfully installed and used Cordova in your Ubuntu.
If you have faced any other issues and found solution for that, please add it in the comments section so that it can help others.

Thanks.

Comments

Post a Comment

Popular posts from this blog

Upgrade your kitchen with latest Tech Gadgets and Make cooking faster

Welcome to our latest blog post, where we embark on an exciting culinary journey to elevate your kitchen experience with cutting-edge technology gadgets. In this fast-paced world, cooking has become more than just a necessity; it's an art form that deserves the finest tools. Join us as we explore the innovative tech solutions that can revolutionize the heart of your home, making cooking not only faster but also more enjoyable and efficient. From smart appliances to intelligent cooking assistants, we'll introduce you to a range of futuristic kitchen companions that are sure to inspire your inner chef and transform the way you create delightful meals for yourself and your loved ones. Get ready to upgrade your kitchen and embrace the future of cooking!  In this blog post, we will narrow down the vast array of available kitchen tech gadgets and present only 10 items, carefully selected based on product ratings, price, and their suitability for Indian kitchens.  Are you a Telegram u

TataSky Refresh after Recharge - Activate after Recharge

If you are using TataSky and doing recharge occasionally and that too after disconnection, this post will be very helpful for you. Most of the time you will not get the channels listed as soon as you make the payment. It will display message to Subscribe for that channel. You can easily get channels back by simply giving a missed a call from your registered mobile number. Note: Make sure your TV and SetupBox is on and showing the error message Give missed call to  +91 80892 80892 (Soft Refresh)   wait for 1 minute and If still not active then try giving missed call to  +91 90405 90405 (Heavy Refresh). Ad: Planning to buy a Best low budget Smart TV? Consider  Acer 109 cm (43 inches) I Series 4K Ultra HD Android Smart LED TV AR43AR2851UDFL (Black)  - You can get this TV as low as for 20,000 Rs - which has Bluetooth, WiFi, Android and good customer ratings (4.4/5). Note: Price based on offers, click on the link to see current price on the web page If the above ste

Duplicate file finder/Remover using perl and SHA1

When you are using a computing devices (either a laptop or PC or a Tab) for your personal use after some time (let take some years) you will realise that your disk is full and most of the space are occupied by duplicate files (Same copy of file located in different locations). For ex: You might have a favourite music file in "My Favourite" folder as well as in the "Album" folder. But finding this duplicate manually is a biggest process. That too if the file names are different OMG!. There are lot of free utilities available to do this in automated way, but if you are a programmer, you will always prefer to do it on your own. Here are the steps we are going to do. This is purely on a linux - Ubuntu system.  (for windows you might need to change the path as per conventions ) Getting SHA1 for all the files recursively in a given directory Compare SHA1 with other files Remove the duplicate file Getting SHA1 of a file Using cpan module   Digest::SHA1 we c