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

Popular posts from this blog

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).

If the above step did not help you, there might be something else going wrong, please contact TataSky Support.

Also note that, this can be done only from your TataSky account registered mobile number.

Happy Watching :-)

My First Post

After lot of thinking and research me too started a blog finally to share my knowledge :-).

Not everybody know everything but also everybody else don't know what we know. So lets share and gain knowledge with Win Win approach.