News

Emulate Ubuntu Touch

Aid development for and generally test out Canonical’s own phone and tablet OS using the Ubuntu Touch emulator

Within the next year we should be getting our first glimpse of Ubuntu phones, powered by Canonical’s own mobile OS: Ubuntu Touch. It’s been available for use on various Nexus devices for just over a year now, however there is an alternative method of using it in the Ubuntu Touch emulator.

The emulator allows you to step into the Ubuntu Touch interface with all the relevant controls you could possibily need in order to properly emulate a phone or tablet. As well as finding out how the interface generally works, it’s an excellent platform for testing out Ubuntu Touch apps and developing for it.

The emulator does not emulate the ARM architecture though, and as such not all the current apps work on it. In the future most, if not all, apps will be able to work across all platforms, including the standard desktop version of the distro.
So, if you don’t want to risk bricking your phone, let’s get started!

Emulate a fully working Ubuntu Touch image to check out the mobile OS or begin development for it
Emulate a fully working Ubuntu Touch image to check out the mobile OS or begin development for it

Step 01 Get the tools repository

If you’re using Ubuntu 14.04 or later you’ll already have the phablet tools repo installed. 14.04 users can skip this step, but for everyone else you’ll need to add the repository so you can install the relevant software. Do this with:

$ sudo apt-add-repository ppa:phablet-team/tools

Step 02 Install the emulator

Press Enter to confirm the PPA and then run an apt-get update for it to populate APT with the new available software. Now you can start the process of installing Ubuntu Touch to a mobile device – but for the emulator you’ll need to do:

$ sudo apt-get install ubuntu-emulator ubuntu-emulator-runtime

Step 03 Create your instance

To start your emulated phone you need to first create an instance by downloading the current image and then running it. Name it whatever you wish but remember its name for the future:

$ sudo ubuntu-emulator create [instancename]
$ ubuntu-emulator run [instancename]

Step 04 Change the architecture

If you’re having issues launching the emulator after building it like this, you can also create an instance with your specific CPU architecture in mind. The safest thing to do on both x86 and x86_64 is to do this:

$ sudo ubuntu-emulator create --arch=i386 [instancename]

Step 05 64 problems

On 64-bit machines, if you’re still getting issues then the solution for now is to install the i386 dev library. It’s a known bug so future versions will fix it, but for now you can install it with:

$ sudo apt-get install libudev1:i386

Step 06 Using the phone

The main way to use your emulated Ubuntu Touch device is by clicking the mouse and moving it to swipe. There’s a little tutorial to help you along the way, however the basics involve swiping down from the top to get settings, swiping from the left for apps and moving between frames by swiping from the right.

Step 07 More usage tips

A click is considered a tap, so use it to tap on apps and further move around the interface. The keyboard is not hooked in so you’ll need to manually type by tapping on the letters with your mouse in order to input text.

Step 08 Orientation

If you’re working on a laptop or don’t have a massive screen, you may not be able to see the entire emulated instance. One way to get around this is to change the orientation of the display to portrait; this can be done in the display settings of most desktop environments. Alternatively, press Ctrl+F11.

Step 09 Exiting

The best way to end the instance is to use the window’s Close button. This will properly save any settings you’ve made and anything you’ve changed to make sure you can turn it back on to its previous state. Trying to kill the script from the terminal will not terminate the instance properly, forcing a restart if you want to be able to use it again.

Step 10

The Ubuntu SDK and Touch emulator is built upon Android and ADB technology, so you can control it using the same commands as you would an Android device. You can find a list of devices and emulators attached with:

$ adb devices

Step 11

While the emulator has SSH installed, it’s not activated by default. You can enter the emulator by using ADB Shell in the terminal. You will then need to access the root account by using:

$ su phablet

Step 12 Start SSH

Once in root we’re going to start the SSH service and then set it so it can autostart after a reboot. We’ll do this with the following commands:

# service ssh start
# setprop persist.service.ssh true
# sudo reboot

The password is phablet.

Step 13 SSH routing

Finally, you’ll need to do some clever routing of the SSH ports to do it via localhost. The emulator software handles most of it, so just do it by entering the below into the terminal:

$ adb forward tcp:9999 tcp:22

Step 14 SSH access

You can now enter into Ubuntu Touch with SSH by using the ssh command. You’ll likely have to enter the password again, and you’ll also need to confirm the SSH credentials of the emulator:

$ ssh phablet@localhost -p 9999

Step 15 ADB access

SSH isn’t the only way to access the emulated image: using ADB as we did earlier can be much quicker, and ADB also has access to specific functions that allow it to work better in editing and updating phone content. As before, you can enter directly into the emulator just by using:

$ adb shell

You are then able to navigate the file system in the same way you would with cd, run commands and install software. As before, the password for the whole thing is phablet if you want or need to run as root.

Strong 16 Take a snapshot

You can create a snapshot of your emulated image to revert to when necessary if changes are to be made. To do this, make sure you first remember the name of it, close down the running image and enter:

$ ubuntu-emulator snapshot --create=pristine [instancename]

Step 17 Reverting snapshots

These snapshots can be useful for reverting back to earlier versions for development purposes. There are two ways of doing it: pristine and normal. Pristine revert goes back to how the snapshot looked when it was first created. This can be achieved like so:

$ ubuntu-emulator snapshot --revert-pristine [instancename]

Step 18 Back to normal

If you want to revert to a later, normal version of a screenshot with extra settings and features that you’ve set up, you can do this with:

$ ubuntu-emulator snapshot --revert=pristine [instancename]

Step 19 Extra key commands

As well as being able to use Ctrl+F11 to change orientation, there are some extra keyboard functions you can use to access hardware keys. These include using F7 instead of the power button and Ctrl+F5 and Ctrl+F6 to decrease and increase volume respectively.

Step 20 Ubuntu SDK

The Ubuntu SDK is used for developing apps on Ubuntu Touch and also includes its own way of connecting to and creating emulators to run your code. The SDK itself can be installed via the following:

$ sudo apt-get install ubuntu-sdk

Step 21 SDK emulator

When the emulator is running you can attach it to the SDK to test your apps and such. To do this, open the Devices tab and go to the Device Actions subtag within that. Click on Redetect devices and your emulator should be added to the Serial number field to select.

Step 22 Keep testing

With the emulator in place and working, you now have full control over what you want to do with it! Testing out the OS as well as testing out apps is a good way to get into Ubuntu Touch for when the phones start hitting the market.

×