Installing Apache Cordova on BunsenLabs Linux

Apache Cordova header image

Installing Cordova wasn't straightforward, so I wrote up what worked for me.

First install Nodejs and create a symlink because it gets installed as nodejs rather than node.

curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node

NPM is thankfully in the debian repos:

sudo apt-get install npm
sudo apt-get install -y build-essential

Install Cordova using NPM and create your first project:

sudo npm install -g cordova

cordova create MyProject
cd MyProject

platform add browser
platform add android

The cordova run browser command requires google-chrome so I installed chromium then symlinked google-chrome to it (you can skip this step if you use Chrome):

sudo apt-get install chromium
sudo ln -s /usr/bin/chromium /usr/bin/google-chrome
cordova run browser

Ta-da! You can now see your project running in the browser, such as it is.

Install the Android Stand-Alone SDK tools, then set the ANDROID_HOME environment variable and add the Android tools to your PATH:

nano ~/.bash_profile
export ANDROID_HOME=~/bin/android-sdk-linux
export PATH=$PATH:$ANDROID_HOME/tools
source ~/.bash_profile

While this article was helpful I was ultimately unable to make the new environment variables persist over reboots, no matter which file I added them to (.bash_profile, .profile, .pam_environment, etc).

Now try and build your new app:

cordova build

If you get an error about being unable to run java -version, you may need to install the JDK and add the JAVA_HOME environment variable:

sudo apt-get install default-jdk
export JAVA_HOME=/path/to/jvm/

If you get the following error:

:CordovaLib:processDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':CordovaLib:processDebugResources'.
> A problem occurred starting process 'command '/home/windlab/bin/android-sdk-linux/build-tools/23.0.2/aapt''

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.785 secs
ERROR building one of the platforms: Error code 1 for command: /home/windlab/projects/AlarmClock/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/windlab/projects/AlarmClock/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true
You may not have the required environment or OS to build this project
Error: Error code 1 for command: /home/windlab/projects/AlarmClock/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/windlab/projects/AlarmClock/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true

It's because you're trying to run a 32bit file on 64bit system. Thanks Abdelraman Elkady!

sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1

Finally, run the following command to display your new app in the Android emulator (if you haven't created one already the error surprisingly gives useful instructions):

cordova emulate android