Some while ago, I used to code with my laptop on my knees in the public transportation. That way, I made significants contributions to rss-atom-bundle and I’m sure this bundle wouldn’t be the same today without it. Meanwhile, coding with a 15'' laptop in the subway means troubles with other passengers or the laptop itself like complaints, purse shots in the screen or a computer getting very hot on your knees. So I decided to keep it home.
But I couldn’t resist, I needed to keep working on open source projects so I tried to do it with a system closed to what I know on a smaller device. The Nexus 7 tablet is a good candidate for that and you’ll see in this post how I managed to set up a development environment using applications available on Google Play. I ended up with the ability to push commits on Github and to run PHPunit inside my projects.
Things to consider before
Before trying this at home (or in the subway) please take the following into consideration :
- some useful features like profiling and step by step debugging are not supported
- you need a 7" screen or higher
- some applications are not free (but none of them are really expensive)
- you can literally do it wherever you want. I’m talking about programming.
- the ability to test the responsiveness of your webapp in real world conditions
To write code using a tablet you’ll need two things : an editor (obviously) and a keyboard.
A lightweight editor with an excellent syntax highlighting. There’s not much to say about it.
Brackets and dollar are not easy to find using a classic Android keyboard. It’s not a big deal for those who write short texts and e-mails, but some weirdos here are trying to type really different things. And those nerds will find happiness using the Hacker’s keyboard.
In other words : don’t try to write code without it. Period.
It supports enough Git features to work efficiently :
- private key authentication
- branch creation, deletion and merge
- Visual history
- show differences since last commit
- ability to revert uncommitted changes
It just lacks cherry-picks and tagging. However the user interface is clean and pleasant to use. really worth the price (less than 2€).
running the code
A PHP execution environment must provide :
- a web server
- PHP 5 in a recent version
- MySQL and / or SQLite with all privileges
- ability to run a PHPUnit suite
It also should provide :
- PHP CLI
As you will see below, every applications in the Google Play Store includes most of the essential items. It’s not the same with PHP CLI and Xdebug, which are quite hard to find.
Free of charge, it comes with :
- lighttpd 1.4.29
- php 5.4.8
- mysql 5.1.62
- phpmyadmin 3.5.3
Obviously, the PHP interpreter will be outdated really soon. Another thing :
You’re not privileged to create a database. Maybe you need to root the device to gain access to it? I’m not concerned by this issue for the moment, but I think it will be a real problem for those who need to work with a database. Xdebug is not supported, so I decided to try something else.
Not free + PHP 5.4 = next
PHP is updated on a regular basis in this application (5.6.2 at the writing of this article), it’s worth giving it a try even though it’s free for only 5 days. This is a powerful app which allows you to customise everything in the servers configuration : PHP, lighttpd, MySQL and so on. However, Xdebug is still missing let’s move on.
Bit Web Server
PHP 5.6.4 is embedded in BWS and after a quick glance at the phpinfo()’s output … It features Xdebug ! Now the PHP CLI : of course it isn’t a feature officially provided by the application, but the executable must be somewhere in the filesystem. Let’s see if it’s mentioned in lighttpd’s configuration :
The line 40 defines the path to the PHP binary. So I tried to execute it in a terminal emulator :
It works. Just set an alias like this in the terminal configuration and you won’t have to type the full path again :
I finally looked at phpmyadmin and I found exactly the same issue androphp suffers from. I think the device needs to be unlocked in order to create databases within MySQL. Anyway, Bit Web Server fits my needs better than the other applications, I’ll stick with it.
Updating dependencies with Composer
The PHP CLI was one of my expectations because I need it to run Composer. So, does it update dependencies like it should ? Let’s see :
Apparently not. This time OpenSSL is not properly supported by the PHP interpreter embedded in BWS. Maybe it could only be a matter of certificate but it’s not, the compilation arguments are not suitable for PHP to support OpenSSL.
You can get rid of this issue by simply copy a fresh vendor directory from a computer to the device. However, it will leave you in a rather uncomfortable position when you’ll need to update your project’s dependencies.
Running PHPUnit tests suite
Now that I properly initialized the project on the device, it’s time to run the tests suite. Unfortunately I can’t really count on the PHP CLI, but never mind, there is still an interpreter suitable to run code through a browser. I consequently wrote a phpunit.php script, here is the source :
/** * Launch PHPUnit in a browser */ $argv = array( '--configuration', 'phpunit.xml.dist', #'--coverage-html', 'coverage/', './tests', ); $_SERVER['argv'] = $argv; require 'vendor/autoload.php'; PHPUnit_TextUI_Command::main(false);
Note what I did at line 8, you can uncomment this line if you need to generate the code coverage report. Now just let’s run the tests suite :
Perfect for test driven development, isn’t it? 90% of feed-io was written that way since march 2015, so even if it’s harder than working with a laptop, you can write code using a Android device.
The stack still have some issues and it’s a matter of time before I set everything right. The next thing to do for that is to unlock the tablet and try to fix all the issues I met until now. I’m confident that the MySQL privilege problem will be solved easily, however I can’t say the same with OpenSSL. Anyway, trying to set up a development environment on an android device is interesting, it forces you to deal with the (many) differences between Android and a classic *nix system. I may write another post on the subject when I’ll find a way to run composer, until then feel free to drop me a line if you have any comments or suggestions on how to run it.