Monthly Archives: February 2014

Setting up a private Android appstore with FDroid

Introduction

There are a number of use cases to create an appstore with private data. As we create and release more devices and products, we are able to create matching AppStores to support them.
Appstores can be a way of controlling the software on the devices accurately, providing speed of update via a local store as opposed to Google Play, and also allows us a lot more flexibility in what we push to devices (agility). Our own curated appstores will also allow us to generate an income stream if we so desire, as well as create a dev community ecosystem for creation of apps for devices.

F-Droid server

FDroid is an Open Source package of server and client applications to deploy an app ecosystem similar to Google Play. The server scripts are written in Python language and the client is written in Java using Android SDK.

The FDroid Repository is an easily-installable catalogue of FOSS applications for the Android platform. The server contains the details of multiple versions of each application, and the Android client makes it easy to browse, install them onto your device, and keep track of updates.

Detailed installation instructions can be found in the official manual.

Prerequisites

Python

You will need a server, with a Python runtime installed. The python runtime should have the following prerequisites installed:
* PIL
* pip
* Python buildtools

Remember to install PIL with JPEG and Zlib support for reading APK files! I.e. install libjpeg and zlib1-dev packages for your OS BEFORE installing PIL with pip!

Android SDK

The Android SDK is used throughout the server to manage and read metadata from the APK files. It is also used for signing, compiling source and numerous other tasks
* Grab the SDK from http://developer.android.com/sdk/index.html
* Update the SDK once unpacked on the server with android sdk update –no-ui
* export ANDROID_HOME to the pwd

FDroid source

Grab the fdroid-server source from Gitorious
* git clone git://gitorious.org/f-droid/fdroidserver.git

Nginx installation

I used Nginx to serve the repo files, as nginx is very well suited to serving static content very quickly. There will be little modifications and no dynamic content as we proceed, so nginx is a good choice. You may use other web servers, but you will be on your own.
* sudo apt-get install nginx (on Ubuntu flavours)
* edit /etc/nginx/nginx.conf to suit your setup
* service nginx start/restart
* The nginx docroot is in /usr/share/nginx/www
* You may need to edit /etc/nginx/sites-enabled and allow directory listing of index.xml too.

Browsing to the IP/hostname of the server should now bring up an nginx placeholder page.

FDroid setup

* Create a directory to hold your repo.
* Copy the file config.py from fdroid. Edit the two following propertis in config.py with appropriate values:
* sdk_path = “/tools/android-sdks” (This should reflect the path of your Android SDK installation)
* repo_url = “http://localhost/fdroid” (this should be your server IP/hostname)
* repo_icon = “icon.png” (this must exist as a 48x48px png)
* Run fdroid update -c This will create a repo and aerchive directory
* Place all APK’s inside the repo directory
* Run fdroid update again. This will unpack and parse all of the APK files and make entries for them
* Done!

You should now be able to browse your repo via a web browser!

Next steps will be to customize the client, which will be on a seperate post

Using QEMU to emulate ARM devices

This post will show you how to set up a QEMU virtual device to play with your ARM code on an x86_64 host. It is quite simple, and you should be able to simply copy and paste into a terminal and get going relatively quickly.

As an example, we will be installing a debian build (wheezy) into your VM.

First off, we need to install the QEMU packages. I use Ubuntu/Mint, so this post will be somewhat biased towards that.

Let’s start off getting the packages we need:

sudo apt-get install qemu-kvm
sudo apt-get install qemu-system-arm
sudo apt-get install qemu-utils

Now we can check that everything is installed OK and ready to go with:

qemu -version

Make a directory to work with and then grab some files off your local debian mirror. Remember, we need the ARM based distro.

mkdir ~/arm-emul
cd ~/arm-emul
wget ftp://ftp.debian.org/debian/dists/wheezy/main/installer-armel/current/images/versatile/netboot/initrd.gz
wget ftp://ftp.debian.org/debian/dists/wheezy/main/installer-armel/current/images/versatile/netboot/vmlinuz-3.2.0-4-versatile

Remember now that depending on your board/device, you may want to check if it supports ARM EL or ARM HF. As you can probably guess from the above filenames, we are working with ARM EL. There are a number of differences between the way (and efficiency) of the two device types, but if you don’t know, then you are probably using an ARM EL device. Also, it is worth checking with your manufacturer if you haven’t built your device yourself, as ARM HF is a way better buy!

Let’s create a virtual HDD now to host the code/OS:

qemu-img create -f raw hda.img 8G

I like to create a drive as big as my devices flash ROM. In this case, it is 8GB. Yours may vary.

Now, lets get the system up and running:

qemu-system-arm -m 256 -M versatilepb -kernel ~/arm-emul/vmlinuz-3.2.0-4-versatile -initrd ~/arm-emul/initrd.gz -hda ~/arm-emul/hda.img -append “root=/dev/ram”

Should get you started with the Debian installer. Do the installation and then close your VM.

Once complete, mount your filesystem, and then copy the relevant files around. You need to do this step as debian will not be able to install the bootloader, so you kind of have to do it manually.

mkdir mount

sudo losetup /dev/loop0 hda.img
sudo kpartx -a /dev/loop0
sudo mount /dev/mapper/loop0p1 mount

cp ~/arm-emul/mount/boot/initrd.img-3.2.0-4-versatile ~/arm-emul/
sudo umount ~/arm-emul/mount

Now you can start up your brand new debian ARM VM with:

qemu-system-arm -M versatilepb -kernel ~/arm-emul/vmlinuz-3.2.0-4-versatile -initrd ~/arm-emul/initrd.img-3.2.0-4-versatile -hda ~/arm-emul/hda.img -append "root=/dev/sda1"

Great! Now off to make your custom OS and flash it to your board! Good luck!