Apache Cordova development environment install on Ubuntu

Apache Cordova has very nice documentation, however as so many projects it focused on the Windows/MacOS duopolies only. Fortunately it’s not too hard to work out the differences.

Apache Cordova Logo

Installing dependencies

Thanks to: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

sudo apt-get install python-software-properties python g++ make ant

Installing Android SDK

Please note: one of the problems I found was that I had some Android tools from the Ubuntu repos that were conflicting with the SDK install. It’s probably a good idea to remove them first. That might save you from a lot of headaches down the line (and time to troubleshoot).

sudo apt-get remove android-tools-adb android-tools-fastboot

Download as per http://developer.android.com/sdk/index.html

wget http://dl.google.com/android/android-sdk_r22.6.2-linux.tgz

Note: check for updated link version obviously

vim ~/.bashrc

Add the PATH variables to the top of the file

#AndroidDev PATH
export PATH=${PATH}:~/android-sdk-linux/tools
export PATH=${PATH}:~/android-sdk-linux/platform-tools

Reload bash variables without reboot / logout

source ~/.bashrc

Testing SDK

android

This command should now bring up the SDK manager.

Installing Eclipse IDE

This is obviously an optional step depending on the IDE you want to use. I have previously covered a manual Eclipse install (as opposed to the Ubuntu repositories).

Install Eclipse ADT Plugin

As per: http://developer.android.com/sdk/installing/installing-adt.html

Node.js Install

The main difficulty on Ubuntu (as with so many development tools – see Eclipse above) is that the included node.js version in the Ubuntu repositories is outdated (remove the Ubuntu version with ‘sudo apt-get remove node’).

sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install python-software-properties python g++ make nodejs

Install Cordova

sudo npm install -g cordova

Check Cordova Requirements

This will check for Android SDK installation, Ant and other dependencies – saving you going through error messages later.

~/.cordova/lib/android/cordova/3.4.0/bin/check_reqs

Create Cordova Project

mkdir ~/projects/PROJECTNAME
cd ~/projects/PROJECTNAME
cordova create ~/projects/PROJECTNAME com.COMPANYNAME.PROJECTNAME PROJECTNAME
cordova -d platform add android
cordova build

Create Eclipse Project

Open Eclipse
Create New Android project from existing sources
Import ~/projects/PROJECTNAME/platforms/android
Test in emulator by right clicking the project and selecting “Run As –> Android App”

Ubuntu Touch install on Nexus 4

This is the last of a series of alternative mobile OS installs and the easiest install by a country mile !

Ubuntu Touch Logo

Install

Everything is quite well documented here: https://wiki.ubuntu.com/Touch/Install.

sudo add-apt-repository ppa:phablet-team/tools
sudo apt-get update
sudo apt-get install phablet-tools android-tools-adb android-tools-fastboot
phablet-flash ubuntu-system --channel devel --bootstrap

That is it really ! This is how a OS change on a mobile should work !

Issues

Ubuntu touch can not yet handle the radio firmware past Android 4.3 devices. So if your N4 was upgraded to Android 4.4 (KitKat) you need to flash the radio to the Android 4.3 (up to Version 2.0.1700.84) else WIFI will not work.

Download 4.3 Stock Image from: https://developers.google.com/android/nexus/images#occamjwr66y

fastboot flash radio fastboot flash radio radio-mako-m9615a-cefwmazm-2.0.1700.84.img
fastboot reboot

Wifi setup

(Optional – this can be done via phone UI as well). Connect the phone via USB

adb shell
nmcli -pretty dev wifi connect NETWORK-NAME password PASSWORD

Install FirefoxOS on Nexus S (GT-9023)

I just had one of my old hand-me-down phones returned by my offspring in a great condition (junior is very careful with his equipment – well done young man !). This doesn’t happen all too often shows that the Nexus S is a decently built phone. This is also a good example of breaking the built-in obsolescence of modern phones. This particular unit has served me well for nearly 2 years (my average is one year) and served 2 kids after that.

These instructions have been compiled on Ubuntu 13.10 64bit to allow me to re-do this process in future. It should work on any Linux based distro (see pre-requisites) – if you are using another Operating System it might be time to switch. Hopefully it might be useful for other people as well.

Installing pre-requisites

As per https://developer.mozilla.org/en-US/docs/Developer_Guide/Build_Instructions/Linux_Prerequisites

wget https://hg.mozilla.org/mozilla-central/raw-file/default/python/mozboot/bin/bootstrap.py
python bootstrap.py

Ubuntu 13.10 additions

As per https://developer.mozilla.org/en-US/Firefox_OS/Firefox_OS_build_prerequisites#Ubuntu_13.10.

sudo apt-get install --no-install-recommends autoconf2.13 bison bzip2 ccache curl flex gawk gcc g++ g++-multilib gcc-4.6 g++-4.6 g++-4.6-multilib git lib32ncurses5-dev lib32z1-dev zlib1g:amd64 zlib1g-dev:amd64 zlib1g:i386 zlib1g-dev:i386 libgl1-mesa-dev libx11-dev make zip libxml2-utils
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 1
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 2
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 1
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 2
sudo update-alternatives --set gcc "/usr/bin/gcc-4.6"
sudo update-alternatives --set g++ "/usr/bin/g++-4.6"

Check out & build Firefox OS

git clone git://github.com/mozilla-b2g/B2G.git
cd B2G
echo "export HIDPI=1" > .userconfig
./config.sh nexus-s
./build.sh -j3

The config script will take quite some time depending on your internet connection as it has to download a lot of data. The build time will depend on your machine. In my case it took xx hours for the config and yy hours for build.

Notes

I had the following error with the config script: https://bugzilla.mozilla.org/show_bug.cgi?id=956098 (workaround contained in comments).

Install on the phone

NOTE: Before doing this you obviously want to backup your phone & data if you have anything useful on there (in my case not necessary).
NOTE: Before doing this step you need to ensure that the Nexus S bootloader is unlocked

  1. Reboot the Nexus S into bootloader mode by pressing volume up + power buttons simultaneously until you see the bootloader screen
  2. Connect the device to the PC via the USB cable
  3. Check the line “LOCK STATE – LOCKED”

If the unit is locked you can unlock it by issuing the following command
fastboot oem unlock
And use the VOLUME key to select + the POWER key to confirm/

Flash the phone

./flash.sh

VOILA !

FirefoxOS Home Screen

Or you can do it manually by using fastboot to copy the images

fastboot erase boot
fastboot erase system
fastboot erase userdata
fastboot flash userdata userdata.img
fastboot flash system system.img
fastboot flash boot boot.img
fastboot reboot

For the people that don’t want or can not (time to upgrade your OS!) build I have uploaded the resulting images (Build Date: 2014-01-20) to GoogleDrive. As usual this comes with a warning – proceed at your own risk !

If you want to return back to the factory Android ROM you can find the Google images here: https://developers.google.com/android/nexus/images

Now this unit will serve as a secondary phone (being compared against Ubuntu Touch on a Nexus N4) while Overseas where I generally need 2 phones.

Thank you Mozilla foundation for all the work and making it available fully in Open Source ! If you haven’t done so it’s time to join here: https://sendto.mozilla.org/

FirefoxOS Browser

Thank you to Google for NOT making it harder than necessary to extend the usefulness of their NEXUS range of phones and tablets. And in the same breath curse you SAMSUNG, APPLE, … ! The reason for me moving phones actually was the fact that the Galaxy S4 is such a P.I.T.A. to get upgraded and get rid of the Samsung bloatware. Back on the Nexus range – in hindsight I should have never left.

SMS Gateway using Sierra Wireless USB Modem on Debian Wheezy

I have been planning to set up a SMS Gateway for sending and receiving SMS messages via a headless utility unit (Raspberry Pi) for a while. Since I had a leftover Sierra Wireless AirCard 880U from Telstra in Australia I wanted to re-purpose this unit with a spare SIM card. Unfortunately it was very hard to find any good setup manual for this particular combination and took some time to fiddle & debug. This is the working setup for future reference and hopefully it helps somebody.

Install dependencies

Note: install usb-modeswitch BEFORE connecting USB Modem
sudo apt-get install usb-modeswitch gsm-utils smstools gammu

Connect the USB Modem

Check if modem is recognised

lsub

Bus 003 Device 002: ID 1199:6855 Sierra Wireless, Inc.

Edit smstools config file

vim /etc/smsd.conf

Change the GSM1 entry
[GSM1]
init = ATE0;+CPMS="SM","SM"
device = /dev/ttyUSB2
incoming = yes
mode = new
baudrate = 115200
smsc = 61418706700
pin = ignore
#rtscts = yes
#cs_convert = yes
report = yes
sending_disabled = no
memory_start = 1
pre_init = yes
primary_memory = SM
secondary_memory = SM
secondary_memory_max = 40

Troubleshooting the modem

I installed gammu purely to have an easier way to test if the modem actually worked. You can use gammu-config to do a GUI config or create a config file manually

vim /etc/gammurc

[gammu]
port = /dev/ttyUSB2
connection = at115200

Testing

gammu-detect

; Configuration file generated by gammu-detect.
; Please check The Gammu Manual for more information.

[gammu]
device = /dev/ttyUSB0
name = Phone on USB serial port Sierra_Wireless__Incorporated AirCard
connection = at

[gammu1]
device = /dev/ttyUSB1
name = Phone on USB serial port Sierra_Wireless__Incorporated AirCard
connection = at

[gammu2]
device = /dev/ttyUSB2
name = Phone on USB serial port Sierra_Wireless__Incorporated AirCard
connection = at

#send sms
sudo echo "sms test" | /usr/bin/gammu --sendsms TEXT +61XXXXXXXX
#check received sms
gammu getallsms

Add your own user account to dialout group if you want to send from your own account for testing (gammu)

sudo adduser $UNPRIVILEGEDUSER$ dialout

Next I will have some fun setting up PlaySMS to allow me to send SMS commands and create some inbound SMS workflows for family.

References
PlaySMS: http://playsms.org/
Gammu: http://wammu.eu/phones/sierra/2551/
smstools: http://smstools3.kekekasvi.com/index.php?p=configure

Connection Android 4.x MTP mass storage to Ubuntu 12.x

The ability to connect Android 4.+ devices to Ubuntu using the USB Mass Storage interface has always been a pain. With Ubuntu 13.04 a new MTP back-end (gvfs-mtp) is going to be introduced, but I have had some issues with the 13.04 Beta so I found this backport PPA to Ubuntu 12.04 and 12.10

sudo add-apt-repository ppa:langdalepl/gvfs-mtp
sudo apt-get update
sudo apt-get install gvfs
sudo apt-get upgrade

Kudos to Phillip Langdale for the work and maintaining the PPA !

Running Android 4.0 (ICS) on Virtualbox

Debugging things on the Android Emulator (incluced in the SDK) can be a very slow and cumbersome process. Thanks to the Android-x86 Project it’s quite easy to run Android in VirtualBox. This is highly useful when you need to test mobile apps and websites from the Android Browser (as well as Chrome Mobile).

  1. Download an Ethernet enabled ISO from Tablets x86

    wget http://dl.dropbox.com/u/75945873/android-x86-4.0-eth0-generic_x86-20120426.iso.torrent
    transmission android-x86-4.0-eth0-generic_x86-20120426.iso.torrent

  2. Create new ViratualBox VM
    VM Settings 1
    VM Settings 2
    VM Settings 3
    Important Settings (see screenshots)

    • OS: Linux, Version: Linux 2.6
    • Enable VTx/AMD-V
    • Use Bridged Network Adapter (if you want to allow direct Internet Access)
  3. Mount the ISO file downloaded previosly and start the VM
    Install dialog
  4. Create the Root Filesystem (ext3) on the VBox .vdi created with the new VM, mark as bootable
  5. Write the Filesystem changes to disk (VDI) and format the disk
  6. Install GRUB Boatloader
  7. Copy files from ISO to VDI
  8. Unmount the ISO image and reboot
  9. Note: You need to disable the mouse pointer integration (if you have installed VirtualBox Client Add-ons) in the menu of Virtualbox (‘Machine’ –> ‘Disable Mouse Integration’) when you start the VM (see screenshot). I have not found a way to disable this by default on Virtualbox on Ubuntu (If anybody has managed this I would love to know how !)

    Disable Mouse Integration

  10. Start the Android Setup Wizard to set locale and you should be up and running (network should already function to test external sites from Android browser) !

Intel Ultrabook tweaks on Ubuntu 12.04

After upgrading my Toshiba Z830 Ultrabook to 12.04 (Precise Pangolin) I noticed that the ability to control the screen back-light was not working using the Toshiba Fn F6/F7 keys.

Thanks to http://www.linlap.com/wiki/acer+aspire+s3 the solution was found quite quickly.

sudo vim /etc/default/grub

This will open the grub configuration file. (Grub is the initial boot selection software)
To be able to dim the screen brightness, You’ve got to modify the line:

GRUB_CMDLINE_LINUX=""

to these two lines:

pcie_aspm=force
GRUB_CMDLINE_LINUX="quiet splash pcie_aspm=force i915.i915_enable_rc6=1 i915.lvds_downclock=1 acpi_osi=Linux acpi_backlight=vendor elevator=noop"

Another neat tip: intel-gpu-tools can be used to control brightness from the commandline.

# will set brightness at 50%
intel_backlight 50


EDIT [2012-08-24]: to avoid issues on resume you need to add a script to the

sudo vim /etc/pm/sleep.d/20_wakeup

Add the following:

#!/bin/bash
case "$1" in
suspend|hibernate)
#do nothing
;;
resume|thaw)
echo 7 > /sys/class/backlight/toshiba/brightness
;;
*)
exit 1
;;
esac
exit 0

Mark the file as executable
sudo chmod +x /etc/pm/sleep.d/20_wakeup

Android 4.0 screenshot functionality on Galaxy Nexus

One of the features I missed since the good old Android 1.5 days was the ability to take screen-shots on the device. Prior to Android 4 (ICS) the only workable way to create screen-shots was to connect via USB cable and use the Android SDK to make remote screen-shots.

On Android 4.0 all you have to do is press Volume Down Key + Power Key down at the same time and hold.  You should hear the camera click (if audio is on) and Android will show a notification that the screenshot was saved on your device and you can now upload or transfer to your favourite service.

Getting a handle on Ubuntu mobile power management

To get an idea on the current power usage and some suggestions on how to improve power-management ‘powertop‘ is a must-have.

sudo apt-get install powertop

Powertop Screenshot

For some more detailed suggestions this is a good start: https://help.ubuntu.com/community/PowerManagement/ReducedPower

Mobile Browser Testing on the Desktop

If you need to check websites for mobile compliance on a regular basis you know that having a device to constantly check is painful and slows down your work during debugging and phases of constant change.

Surrounding myself with screens by adactio, on Flickr
Creative Commons Attribution 2.0 Generic License  by  adactio 

There are a few tools that will make this work a lot easier:

Google Chrome

Chrome does have some nice dedicated plug-ins to help with this task

Firefox

I am not aware of any plug-ins like Chrome, but as a hack I have found it useful to employ a user-agent switching plugin to trick the browser

User Agent Switcher (http://chrispederick.com/work/user-agent-switcher/) works well for this.

  1. Download the User Agent Switcher Add-on for Firefox
  2. Restart Firefox for the add-on change to take place.
  3. To start a new browsing session using an emulated browser, go to Tools > User Agent Switcher and select the appropriate mobile web browser you want to emulate
  4. To switch back to normal browsing, just select the default option from the above menu.

If you need more specific UA Strings check here: http://www.zytrax.com/tech/web/mobile_ids.html

For more serious work there are obviously dedicated emulators from the major Mobile OS vendors (but they need to be installed and configured for each platform):

 

PS: Nothing substitutes final QA testing on actual devices …