Install to ADB: installing packaged Firefox OS apps to USB connected phones (using ADB)

I abhor repetition, so I'm always looking for opportunities to improve my processes. Spending a bit of time early on can save you so much time on the long run!

If you're trying to build something that can only run in devices (for example, apps that use WiFi direct), pushing updates gets boring really quickly: with WebIDE you have to select each USB device manually and then initiate the push.

So I decided I would optimise this because I wanted to focus on writing software, not clicking on dropdowns and etc.

And thus after a bit of research I can finally show install-to-adb:

In the video you can see how I'm pushing the same app to two Flame phones, both of them connected with USB to my laptop. The whole process is a node.js script (and a bunch of modules!).

The module is not in npm yet so to install it:


npm install git+https://github.com/sole/install-to-adb.git 

And then to deploy an app to your devices, just pass in the app path, and it will do its magic:


var installToADB = require('install-to-adb');

installToADB('/path/to/packaged/app').then(function(result) {
    console.log('result', result);
    process.exit(0);
});

Guillaume thinks this is WITCHCRAFT!

https://twitter.com/g_marty/status/577787955269496832

... and I wouldn't blame him!

But it is actually just the beauty of port forwarding. What installToADB does is enumerate all connected ADB devices, then set up port forwarding so each device appears as a port in localhost, and then from there it's just the same process as pushing to a simulator or any other firefox client: we connect, get a client object, and install the app using said client. That's it!

Other artifacts

One of my favourite parts of writing code is when you refactor parts out and end up producing a ton of interesting artifacts that can be used everywhere else! In this case I built two other modules that can come in handy if you're doing app development.

push-app

This is a module that uses a bunch of other node-firefox modules. It's essentially syntactic sugar (or modular sugar?) to push an app to a client. In the process it will make sure there are no more copies of it installed, and also will return you the app once it's installed, so you can do things such as launching it or any other thing you feel like doing.

Using it is similar to using other node-firefox modules:


pushApp(client, appPath);

and it returns a promise, so you can chain things together!

It's not on npm, so...


npm install --save git+https://github.com/sole/push-app

sample-packaged-app

I also noticed that I kept copying and pasting the same sample app for each demo and that is a big code smell. So I made another npm module that gives you a sample packaged app. Once you install it:


npm install --save git+https://github.com/sole/sample-packaged-app

you can then access its contents via node_modules/sample-packaged-app. In node code, you could build its full path with this:


var path = require('path');
var appPath = path.join(__dirname, 'node_modules', 'sample-packaged-app');

and then use it for example with installToADB :-)

Not in node-firefox and not on npm?

You might have surely noticed that these modules are not in node-firefox or in npm. That's because they are at a super proof of concept stage, and that's why they are not even named with a node-firefox- prefix.

On the other hand I'm pretty sure there's people who would appreciate being able to optimise their processes today, and nothing stops them from installing the modules from my repositories.

Once the modules become 'official', they'll be published to npm and updating the code should be fairly easy, and I will transfer the repositories to the mozilla organisation so GitHub will take care of redirecting people to the right place.

Hope you enjoy your new streamlined process! ;-)