Saturday, September 20, 2014

Running Android apps in Chrome is great for developers

This week @vladikoff released a tool that builds on Google's own Android-apps-on-ChromeOS work to allow anyone to run Android applications in Chrome on Linux! I've tried it out on Xubuntu 14.04 and it works quite well. With a few tweaks this is a better way to test applications than the slow Android emulator.

Unfortunately this doesn't work in Chromium - currently version "37.0.2062.94 Ubuntu 14.04 (290621) (64-bit)" - but did work in the latest Chrome for Linux (Version 37.0.2062.120 (64-bit)).

After installing Chrome from the official Google download site, here is how I installed ARChon:

sudo apt-get install npm nodejs-legacy
sudo npm install chromeos-apk -g
wget https://bitbucket.org/vladikoff/archon/get/v1.0.zip
unzip v1.0.zip
Then load the unpacked extension as shown on the archon page.

While most news has been about running Flappy Birds or whatever other app (try Pixel Dungeon), as a developer I was interested in debugging my own Android apps. To do this I needed to install these apps first.

It's actually pretty easy to install an APK - first create a manifest and the extension structure. For Chaos I do this:

chromeos-apk -a ~/projects/chaos-portable-build/android/port/android/bin/chaos-debug.apk
Then from within Chrome, load the unpacked "extension" (ie. the Android app/game) the same way as the main archon runtime. It'll appear on the chrome://extensions page.

App as a extension in Chrome
Running your own APK may work.. or maybe it has a few problems. In order to debug things you should add enableAdb in the manifest.json file, in the arc_metadata section:

"enableAdb": true,
enable adb in manifest.json
After clicking Reload on the extensions page you can run adb logcat and see the output of your app. This may help you find out why it crashes so much. Heh.

Some things I've found are that NDK works if you compile for x86, but the GLES emulation has a few niggles. For example GL_EXTENSIONS reports that the runtime supports GL_OES_draw_texture but when I used glDrawTexiOES it crashed. Also I disabled some GL capabilities that the game doesn't use, but as the runtime doesn't support these capabilities it also crashed.

Finally, in another app I'm making, I noticed that sharing has a few buglets. On a regular Android device you can request information about an intent to share data like this:

Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
ResolveInfo info = getApplicationContext().getPackageManager().resolveActivity(shareIntent, 0);
When no application to share with is available for "text/plain" then it returns null. On ARC it returns an object, but the info.resolvePackageName is null. There are probably a load of small interoperability bugs like this, which is why this wasn't officially released by Google yet.

Either way, this is a great way to test out Android apps if you don't have a phone handy. It's much better than the emulator, finally approaching the simulator approach that everyone has been clamouring for. Get it now before the lawyers at Google send Github a DMCA takedown notice ;-)


Wednesday, September 10, 2014

Toggle Javascript Enabled in Firefox for Android

The add-on for Firefox that I mentioned last time is finally available on the Mozilla add-ons site. This adds a enable/disable JavaScript toggle option to the Tools menu on Firefox for Android.

Screenshot of JavaScript toggle in the Tools menu


The code is on github if you want to see how to make a simple Firefox Add-on. It took me longer than it should have to write this, as I had trouble finding documentation on the technique to read/write a global preference. The code (in JavaScript, ironically enough) is about 120 lines. Only 30 of those are really the meat of the add-on.

Comments and ratings would be helpful. I use this add-on every day to save on bandwidth and battery. The one feature I may add is to have the page reload when you enable JavaScript again, but even that might be too much feature-creep.