Mozilla

It’s an interesting time to be a web developer!

For years Apps have been eating the web and now we are seeing the Web eat the OS. Mozilla is pushing for a world where you can write standards-based, Open Web Apps. These apps should install as native apps and just work, regardless of the platform.

Packaged App on Firefox OS

With the new Firefox for Android, we will now automatically convert your Open Web App into a native Android app.

Packaged App on Android

But how can you test you app on Android, before you submit it to the Marketplace?

We have a new tool to add to your lineup!

Introducing mozilla-apk-cli

If you have NodeJS as well as zip/unzip installed, then you can use our new command line tool to build testable .apk installers.

mozilla-apk-cli is a command-line application, so the commands below would be run from a terminal application.

Getting setup is easy:

npm install mozilla-apk-cli

This will give you a new program mozilla-apk-cli available in ./node_modules/.bin/

You can also globally install with

npm install -g mozilla-apk-cli

I’ll assume you put ./node_modules/.bin in your path or installed globally.

Open Web Apps come in three flavors and the CLI can build them all:

  • hosted app
  • packaged app zip file
  • packaged app from a directory of source code

Let’s assume you have a packaged app you are working on.
You have a directory layout like this:

www/
   index.html
   manifest.webapp
   css/
       style.css
   i/
     icon-256.png
     icon-128.png
     icon-60.png
   js/
      main.js

You can build a testable Android app with the following:

mozilla-apk-cli ./www my_test_app.apk

This will produce my_test_app.apk which can be side-loaded to your phone in either of the following ways:

  • Put in on the web and download/install form a browser on your Android device
  • Use adb to install the app
adb install my_test_app.apk

Setting up adb is out of scope for this blog post, but the Android SDK site has some good resources on adb.

adb using USB

Distribution

Do not distribute this test .apk file!!!

If you change your app, rebuild and send the APK to your users, the update will fail to install. With each new version of your app, using Android’s app manager, you have to remove the test app before installing the 2nd version.

mozilla-apk-cli is only for testing and debugging your new Android app locally. When you are happy with your app, you should distribute the Open Web App through the Marketplace or from your website via an install page.

You don’t need to manage an .apk file directly. Just like you don’t need to manage Mac OS X, Windows or Linux builds for your Open Web App.

We’ve baked native Android support deeply into the Firefox for Android runtime. When a user chooses to install an Open Web App, the native app is synthesized on demand using the production APK Factory Service. This works regardless of the website or Marketplace you are installing the Open Web App from.

How does the CLI work?

Back to our new test tool. This tool is a frontend client to the APK Factory Service. It takes your code and sends it to a reviewer instance of the service. Reviewer as opposed to the production release environment.

This service synthesizes an native Android app, builds it with the Android SDK and lastly signs it with a development cert. As mentioned, this synthesized APK is debuggable and should not be distributed.

The nice thing about the service is that you do not have to have Java, ant, the Android SDK and other Android development tools installed on your local computer. You can focus on the web and test on whatever devices you have handy.

Hosted and Packaged Zip files

We just looked at how to test a packaged app which is a directory of source code. Now lets look at the other two modes. If you already have built your packaged app into a .zip file, use:

mozilla-apk-cli ./my_app.zip my_test_app.apk

If you are building a hosted app, use:

mozilla-apk-cli http://localhost:8080/ my_test_app.apk

No Android Devices? No stress

Perhaps you are saying "Sounds cool, but I don’t have any Android devices… How am I supposed to test?"

Good point. We’re enabling this automatically.

On the one hand, don’t worry. One thing mobile first development has taught us, is that there are way more devices and platforms that you will ever have testing resources for. The web is about open standards and progressive enhancement.

Your web app is just going to be a little bit nicer as a native android app, fitting into the OS as the user expects.

It doesn’t use native UI widgets or anything like that, so extensive testing is not required. The rendering engine is gecko from the already installed Firefox for Android.

On the other hand… open standards and compatibility is a nice story, but as web developers, we know things tend to have platform specific bugs. I’d recommend the traditional grading of supported platforms and if Android is a high priority, definitely get a device, Firefox for Android and test your app.

As we make native experiences automatic across platforms (Android, Mac OS X, etc) we are all ears for feedback. What do you think?

mozilla-apk-cli Resources

The source code for the CLI tool is on GitHub. If you need a sample packaged app, here is a demo version. The source code for the APK Factory Service is also on GitHub.

Join us in with ideas, feedback and questions and please file bugs in Marketplace Integration.

Thanks to Wil Clouser for the illustrations.

17 comments

Comments are now closed.

  1. Sekander wrote on June 12th, 2014 at 02:41:

    Please shorten the name “mozilla-apk-cli”.
    too lazy to type :P

    1. Austin King wrote on June 12th, 2014 at 09:40:

      Sorry about that ;) Depending on your shell, maybe you can do something like

      alias apk=”mozilla-apk-cli”

  2. Antoine Turmel wrote on June 12th, 2014 at 02:48:

    What’s the point of making an apk file if you can’t distribute it ?
    I mean it’s already possible to test your own app using Firefox for Android…

    1. Fawad Hassan wrote on June 12th, 2014 at 03:18:

      In simple words, Android users can get your Open Web App from “Firefox Marketplace” using Firefox for Android and to submit your app on this marketplace don’t need to create apk file. Instead you need to follow the same process like you do when submiting an app for Firefox OS.

    2. Austin King wrote on June 12th, 2014 at 09:32:

      Fawad Hassan and David Bruant did a great job of answering question.

      1) mozilla-apk-cli is a development and testing tool

      2) You distribute your Android apps through Mozilla Marketplace OR another Marketplace OR your own install page on your own website.

      We’ve built the APK Factory to be an open service which powers the web, not just the Mozilla Marketplace. It works via mozApps APIs you would use to build an install page.

  3. David Bruant wrote on June 12th, 2014 at 02:58:

    “mozilla-apk-cli is only for testing and debugging your new Android app locally. When you are happy with your app, you should distribute the Open Web App through the Marketplace or from your website via an install page.”
    => People on Android are used to finding their apps in Google Play. That’s also a place where people discover Android apps. Is there a way to generate an app that can be distributed through that channel?

    “We’ve baked native Android support deeply into the Firefox for Android runtime. When a user chooses to install an Open Web App, the native app is synthesized on demand using the production APK Factory Service. This works regardless of the website or Marketplace you are installing the Open Web App from.”
    => Does this work with another browser than Firefox for Android? According to various sources, the market share of Firefox for Android is somewhere along 2-3%. It seems unrealistic to expect users to be on this mobile browser when we want them to download their app.

    With mozilla-apk-cli updates looks tricky. What’s the update story for the synthesized app?

    1. Austin King wrote on June 12th, 2014 at 09:02:

      > With mozilla-apk-cli updates looks tricky. What’s the update story for the synthesized app?

      Firefox for Android does a daily ping to check for updates. If your manifest changes, then it indicates the app needs an update. The user can choose to update your app.

  4. Thomas wrote on June 12th, 2014 at 05:49:

    So this is only supposed to work with apps that are written for Firefox for Android. Pure Firefox OS apps (e.g. privileged) that access the sdcard etc. won’t work like this?

    By the way, with my app I get a problem with manifest.webapp whenever I use the packaged zip-format as input – it complains “Parameter ‘url’ must be a string, not undefined”. But when I don’t zip, but directly provide the app in a directory, everything works fine.

  5. Robert wrote on June 12th, 2014 at 06:36:

    I hope this apk geeneration fails miserably on the user hands. This will only encourage people to disable the “Install from other sources” protection of their devices, and then be the target of malware sites/ads that encourage you to install random apk from the internet.

    I understand the need of an apk in order for the web app to be easily identified on the system as something different from Firefox, but I think the way to do it is work on new secure APIs on Android to do that, maybe propose it to Google, or contribute something to AOSP

    1. Luke wrote on June 12th, 2014 at 07:22:

      Do you mean install from non-market sources option in Android? Ironically, Google Play is possibly the biggest security hole in Android – considering anyone with hacked Google account could have any app installed (http://nakedsecurity.sophos.com/2011/02/04/android-market-web-store-backdoor-phone-hackers/)

      Furthermore Google Play apparently doesn’t have the human-vetted system that Mozilla has, resulting in an outbreak of bogus / malware apps once in awhile: http://www.infoworld.com/d/security/report-android-malware-and-spyware-apps-spike-in-the-google-play-store-236702

      The installation of FirefoxOS apps should be transparent to the user – you just install from Firefox’s market :)

      1. Robert wrote on June 12th, 2014 at 09:04:

        No I mean people enabling the “allow thrid party applications” security setting on Android, because they trust Firefox to request that when they install an app from the Marketplace, and then visit a website with malware on site or via ads and install it because they are using Firefox.

        It is adding the perception that Firefox is trusted to install external apk files, and then websites using that user perception to their advantage.

        I am sorry but Firefox requesting people to disable the Android protection make me not recommend Firefox anymore for Android

        1. Bill Walker wrote on June 12th, 2014 at 10:05:

          Hi Robert,

          We share your frustration with the tradeoffs we have to make on Android regarding security versus openness, as I’m sure Amazon does as well. For example, it would be cool if we could ask people to trust apps they install from marketplace.firefox.com rather than from all sources. Unfortunately, I don’t think we have that option.

          We, along with third-party native android app stores like Amazon, chosen to ask users to enable the third-party application setting because we think the benefits to users of our ecosystem outweigh the risks of doing so. We believe our security model and strict control over permissions for web apps means that the Firefox Marketplace apps that users install on their Android devices will be safe.

  6. Mte90 wrote on June 12th, 2014 at 06:50:

    It’s possible use the remote debug with this solution?

    1. Austin King wrote on June 12th, 2014 at 08:57:

      Yes, the APKs from this CLI tool are remote debuggable.

  7. Austin King wrote on June 12th, 2014 at 08:53:

    > So this is only supposed to work with apps that are written for Firefox for Android. Pure Firefox OS apps (e.g. privileged) that access the sdcard etc. won’t work like this?

    “Pure Firefox OS apps” should work fine eventually.

    This is about standards based web development, not about developing apps for a specific platform.

    We’re working on enabling all the web intents and Web APIs with their native Android counterparts.

    1. Thomas wrote on June 12th, 2014 at 09:08:

      Thanks for your answer!

      So at the moment navigator.getDeviceStorage(“sdcard”) is not supported but it’s planned for the future? Is it possible to estimate how long it will take until developers can use this feature?

      1. Myk Melez wrote on June 12th, 2014 at 09:55:

        Bug 886627 tracks enabling the device storage API, and it’s currently marked as “tracking Fennec 33″, which means we expect to fix it in that release of Fennec (although it isn’t guaranteed).

Comments are closed for this article.