1. AOSP Plus
AOSP builds with batteries included
James Puderer
Ottawa Android User Group
May 13th, 2013
+
2. What is AOSP?
● AOSP is the Android Open Source Project.
● It contains all of the open sourced components of
Android.
● You are free to download, modify, build, and distribute
AOSP1
● You can find instructions on downloading and building
AOSP at http://source.android.com
● AOSP can be built for most of the recent Google
branded devices (Nexus).
○ Nexus Galaxy
○ Nexus 4, 7, 10
○ Nexus S (<= 4.1)
○ Motorola Xoom (<= 4.1)
3. What AOSP isn't?
What is it missing?
● It may be missing some drivers
○ You can get some of the proprietary drivers for your build: https:
//developers.google.com/android/nexus/drivers
○ Not all of the drivers are are available. (e.g. Camera and GPS don't
work on Galaxy Nexus.)
● It doesn't contain many of the Google applications and
frameworks:
○ Play Store
○ Google Maps
○ Youtube
○ Face unlock
○ etc.
● Not exactly the same as a commercial device
○ In fact, it looks pretty much like the emulator.
4. Why? (does this matter)
● Making changing to AOSP
● Seeing what kind of effect these would have
on a real phone.
● For example:
○ Enabling SEAndroid enforcement and to see what
effect it would have on a real phone (with the Play
store).
○ Developing an Embedded Android system, but gosh
it would be nice if your device had the Play store
during development
5. How?
1. Build AOSP1
2. Create vendor directories2
3. Extract factory system image
4. Deodex APK and framework files
5. Identify the components you need
6. Tailoring the vendor Makefiles
7. Profit!
6. If you're new to building AOSP
I recommend this book!
7. Build AOSP
Go here: http://source.android.com/source/index.html
...and do what it says.1
If you haven't done this before, I'll see you in a day or
two.
If you're successful, you should be able to flash a basic
AOSP image onto your device.
OK? Good?
8. The aospplus templates include directories and Makefiles for
Nexus Galaxy, Nexus 4, and Nexus 7
For the purposes of this tutorial, we'll focus on building for the
Nexus 4 (codename: mako).
However, the same approach could be used for any of the
other device, and extended to include new devices.
Create the vendor directories
Use my template on Github
$ cd $ANDROID_BUILD_TOP
$ cd vendor 1
$ git clone git://github.com/jpuderer/vendor-aospplus.git aospplus
9. Include our directory in the build
--- BoardConfigVendor.mk.orig 2013-05-03 17:11:09.705229512 -0400
+++ BoardConfigVendor.mk 2013-05-03 17:14:37.085224121 -0400
@@ -17,3 +17,4 @@
-include vendor/broadcom/$(LOCAL_STEM)
-include vendor/lge/$(LOCAL_STEM)
-include vendor/qcom/$(LOCAL_STEM)
+-include vendor/aospplus/$(LOCAL_STEM)
--- device-vendor.mk.orig 2013-05-03 17:10:30.393230534 -0400
+++ device-vendor.mk 2013-05-03 17:09:51.393231548 -0400
@@ -17,3 +17,4 @@
$(call inherit-product-if-exists, vendor/broadcom/$(LOCAL_STEM))
$(call inherit-product-if-exists, vendor/lge/$(LOCAL_STEM))
$(call inherit-product-if-exists, vendor/qcom/$(LOCAL_STEM))
+$(call inherit-product-if-exists, vendor/aospplus/$(LOCAL_STEM))
In order for our aospplus components to be added to the build,
we need make sure they get included by one of the mako
device's Makefiles.1
10. Extract factory system image
Download factory image and extract system.img file
Download a factory image for your device. For Nexus
devices, these can be downloaded from here:
https://developers.google.com/android/nexus/images
The factory image will contain a zip file, which will contain a
system.img file. This file contains the compressed ext4
filesystem for the device's /system directory.
Make a copy of this file somewhere you can work on it.
11. Extract factory system image
Extract the file tree from the system.img
$ cp $ANDROID_BUILD_TOP/out/host/linux-x86/bin/simg2img ~/bin
$ simg2img system.img system.full.img
$ mkdir system.mnt
$ mkdir system.factory
$ sudo mount -n -o loop system.full.img system.mnt
$ sudo cp -r system.mnt/* system.factory
$ sudo umount -n system.mnt
$ sudo chown -R ${USER}. system.factory 1
$ rmdir system.mnt
$ rm -r system.full.img
The system.img file packaged with most phones is effectively a
ext4 filesystem that has been compressed. You can expand it
by using the simg2img tool that is built as part of AOSP. Once
the image has been expanded you can loopback mount it as you
would any other filesystem image.
12. Compare system images
Figure out what AOSP is missing
Next, we want to compare the AOSP system directory with the factory system directory, to see what
components and configuration files we might be missing.1
I usually keep a pristine copy of system.factory and a system.aosp directory around for this purpose.
$ cp -r $ANDROID_BUILD_TOP/out/target/product/ mako/system system.aosp
$ diff -qr system.aosp system.factory
$ ...
You will need to use this information later to configure the vendor/aospplus/device/Makefiles. You'll want to come back
to this when you start modifying the Makefiles.
If you're using the aospplus template for one of the defined devices, you may not need to wory about this. Since we're
assuming the mako device (Nexus 4), this analysis has already been done for you.
13. Deodex the APK and framework files
...but first, what is odexing/deodexing?
An odexed file is basically an APK that has been preoptimized for fast loading. The .dex file that
normally exists inside the APK or JAR file (which are really just a zip files) is removed from the APK,
optimized, and is placed next to the .apk as an .odex file.
The Android build system can be configured to preoptimize the files on APK files in /system/app, and
this is exactly what's happened to the factory images.1
The documentation for dexopt details the optimizations:
https://github.com/android/platform_dalvik/blob/master/docs/dexopt.html
Unfortunately for us (and themers in general), the optimized .odex file has dependencies on the
classes in bootstrap class path, which for Android is everything under /system/framework. If we
change the framework files, the .odex files will not work.
So we need to "deodex" the the .odex files, and package them back into the APK and JAR files.
To do that, we need to use some tools to recompile the odex files back into odex files.
You can find the tools here:2
https://code.google.com/p/smali
14. Deodex the APK and framework files
Using the deodex.py script provided with the aospplus templates
$ cd $ANDROID_BUILD_TOP/vendor/aospplus/
$ cp -r $MY_SCRATCH_DIR/system.factory mako/proprietary/system
$ utils/deodex.py mako/proprietary/system
Feel free to do some cleanup of the system directory if you wish, since not all files are needed.
$ cd mako/proprietary/system
$ rm -Rf bin build.prop fonts lost+found xbin
15. Tailoring the Makefiles
Android.mk and device-partial.mk
There are two make files that you will need to tailor for your device.
vendor/aospplus/mako/proprietary/Android.mk tells AOSP how to install the prebuild each of the APKs
from the factory image.
vendor/aospplus/mako/device-partial.mk actually declares what will be added to the final system
image for our device.
● List of APKs to install1
List of files to copy
● Overrides for the device's system properties
16. Tailoring the Makefiles
Android.mk
LOCAL_PATH:=$(call my-dir)
ifeq ($(TARGET_DEVICE),mako)
...
include $(CLEAR_VARS)
LOCAL_MODULE := CalendarGoogle 1
LOCAL_SRC_FILES := system/app/$(LOCAL_MODULE).apk
LOCAL_OVERRIDES_PACKAGES := Calendar 2
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_OWNER := google 3
LOCAL_MODULE_TAGS := optional
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)
...
endif
Declare the prebuild APKs you wish to include from the factory
image.
17. Tailoring the Makefiles
device-partial.mk
PRODUCT_COPY_FILES +=
vendor/google/mako/proprietary/system/media/bootanimation.zip:
system/media/bootanimation.zip:google 1
...
PRODUCT_PACKAGES +=
Books
BrowserProviderProxy
CalendarGoogle
... 2
PRODUCT_PROPERTY_OVERRIDES +=
ro.facelock.black_timeout=1250
ro.facelock.det_timeout=1500
...
Declare the APKs and other files you wish to include in your
build, along with any system properties you need to override.
18. That's it!
Build and be merry.
This should do it:
$ cd $ANDROID_BUILD_TOP
$ make installclean & make -j8
For the truly paranoid:
$ make clobber & make -j8
Questions?
Rebuild AOSP for your device as you did at the beginning.