Compile Android Kitkat on Ubuntu 14.04

Posted by & filed under Tips.

Android Kitkat logo

Latetly I have been trying to compile Android 4.4 Kitkat from the sources on a raw Ubuntu Trusty Tahr (14.04 LTS).
Sure everyone is looking on Lollipop and its successors these days, but yet a lot of boards do not provide for support for it yet so this might be interesting for someone.

Kitkat was built with toolchains older than the current Ubuntu LTS, so if you religiously follow the instructions you can find on source.android.com or XDA-University, you might encounter some problems. Here is a step by step guide to create your build environment.

Consider it a replacement for the official page named :

Initializing a Build Environment

Setting up a Linux build environment

Installing the JDK

Gingerbread through Kitkat requires Java 6 to compile. Not only they require Java 6 but they require the JVM from Oracle, and not openjdk.

There’s a Launchpad PPA (Personal Package Archive) maintained by webupd8.org, a popular Ubuntu Linux blog, which provides the most recent installers to automatically download and install Oracle Java JDK6/7/8/9 from oracle website.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java6-installer
sudo apt-get install oracle-java6-set-default

You can check you’re running the correct Java version by running

java -version

Installing required packages (Ubuntu 14.04)

You will need a 64-bit version of Ubuntu.

Here are the necessary package from Google, minus zlib1g-dev:i386 that is not found in the repo.

sudo apt-get install bison g++-multilib git gperf libxml2-utils make zip

Then you will miss these packages (I found out when trying to build), flex is used during the build process, and lib32z1 provides libz.so.1 that’s missing because we could not install zlib1g-dev:i386

sudo apt-get install flex lib32z1

Then you’re all set and can continue through the next step : Downloading the Source

FormUrlEncodedContent with support for array values

Posted by & filed under Dev', Tips.

As convenient as System.Web.Http is for .NET developers, while working on my current project, I discovered that it did not support array values out of the box.
When you want to post something in the ‘x-www-form-urlencoded’ form, and using the FormUrlEncodedContent class, you are limited to string keys and values as FormUrlEncodedContent is build out of an IEnumerable<KeyValuePair<string, string>> (or more commonly a Dictionary<string, string>) object.

What if I want to send an array like :
POST http://dev.someserver.fr/0.2/theaters/set HTTP/1.1
Accept: */*
Content-Length: 40
Accept-Encoding: identity
Connection: Keep-Alive
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
User-Agent: NativeHost
Host: dev.cinetime.fr
Pragma: no-cache
theaters=["LI38249","LI20271","LI20306"]

Well you can’t. Or you could rewrite and extend FormUrlEncodedContent.
Or you could just reuse the following gist, because that’s precisely what I’ve done :

Note that I only needed (thus added) support for array string values, it can be extended for array keys, array of numeric values, …