Testing Your Native Android App

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.

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

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

npm install mozilla-apk-cli

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

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

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

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?

Technical Evangelist & Editor of Mozilla Hacks. Gives talks & blogs about HTML5, JavaScript & the Open Web. Robert is a strong believer in HTML5 and the Open Web and has been working since 1999 with Front End development for the web - in Sweden and in New York City.
He regularly also blogs at http://robertnyman.com and loves to travel and meet people.

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.

“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?

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.

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

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

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.