LayerCake: Application Embedding for Android

Disclaimer: Use the LayerCake research prototype and demo applications
for academic purposes only and at your own risk. View the license here.

Before you start

This guide assumes that you have:

It is strongly recommended that you use the nandroid tool provided in a custom recovery firmware such as ClockWorkMod to backup your current system before flashing new images to your device.


Step 1: Building LayerCake

Step 1(a): Get the Android source code

LayerCake uses the "android-4.2_r1" tag of the Android source code. Follow the instructions on source.android.com for obtaining and building Android. Use the -b android-4.2_r1 branch option for repo when checking out the source code. If you are already familiar with getting and building the Android source code, the following commands summarize the steps:
% mkdir -p ~/layercake/
% cd ~/layercake
% repo init -u https://android.googlesource.com/platform/manifest -b android-4.2_r1
% repo sync
... wait
Note: At this point, it is recommended that you build Android without any modifications. This will ensure that any build errors for your environment are resolved and are not confused with LayerCake build errors. For example:
% . build/envsetup.sh
% lunch 1
% make -j4
... wait
% emulator
... ensure the build works

Step 1(b): Get the LayerCake source code

Download the LayerCake local_manifest.xml and place it in ~/layercake/.repo or copy and paste the following content into .repo/local_manifest.xml.
<manifest>
  <remote name="github" fetch="git://github.com" />
  <remove-project name="platform/frameworks/base"/>
  <project path="frameworks/base" remote="github" 
    name="Android-LayerCake/android_platform_frameworks_base"/>
</manifest>
Next, pull the source code.
% cd ~/layercake
% repo sync
% repo forall frameworks/base -c 'git checkout --track github/master && git pull'

Step 1(c): Get proprietary binaries

Both the Nexus S and Galaxy Nexus require proprietary binaries not included in the AOSP release. Download the correct version of these files for your device from Google. Then extract the files in your source directory (~/layercake in the examples above).

Step 1(d): Build LayerCake

Now we can build LayerCake. For the "lunch" command, replace <target> with the correct value for your device: full_crespo-eng for Nexus S, full_crespo4g-eng for Nexus S 4G, full_maguro-eng for Galaxy Nexus (GSM/HSPA+), full_toro-eng for Galaxy Nexus (Verizon), or full-eng for the Android emulator.

% . build/env_setup.sh
% lunch <target> # (replace <target> with correct value for your device)
% make clean
% make -j4
If you've built the emulator, you should now be able to launch it by simply executing the emulator command. If you've built a system image for a device, proceed to Step 2 (Installation).


Step 2: Installing LayerCake

In order to flash new images, the phone must be connected to the development PC via USB and booted in fastboot mode. Start with the phone powered down, then hold down the "volume up" button (Nexus S) or both "volume up" and "volume down" buttons (Galaxy Nexus) and press the power button. (Alternatively, you can use ADB to reboot into the bootloader by issuing the adb reboot bootloader command.) If you have problems using fastboot to flash your device, please refer to the documentation at source.android.com.

If you have not already unlocked your bootloader, first issue the following command to unlock the bootloader:

% fastboot oem unlock
Then, follow the on-screen instructions on the phone to unlock the bootloader. Please note that this will void your warranty.

Before flashing images to your device, we reiterate our previous recommendation: It is strongly recommended that you use the nandroid tool provided in a custom recovery firmware such as ClockWorkMod to backup your current system before flashing new images to your device.

After building LayerCake:

Flash the images that you built in Step 1 above. Replace <device> with the correct value for your device: crespo for Nexus S, crespo4g for Nexus S 4G, maguro for Galaxy Nexus (GSM/HSPA+), or toro for Galaxy Nexus (Verizon).
% cd out/target/product/<device> # (replace <device> with correct value for your device)
% fastboot flash boot boot.img
% fastboot flash system system.img
% fastboot flash userdata userdata.img


Acknowledgement: These instructions are based on those provided for building and installing TaintDroid.