Howto Build Android KitKat (4.4) for the Google Nexus 5

December 1, 2013

[Screenshot of Kit Kat AOSP Running on the Google Nexus 5]

NOTE: If you know what this is, and just want to start with a basically working source tree, skip to the section titled “Just Build the Thing ™.”


This page describes the steps necessary to compile the Android Open Source Project (AOSP) sources into a working phone image for the Google Nexus 5 (Here-forth called “hammerhead.”)

If the process of building Android sources is new to you, please start by reading the Android documentation on “Downloading and Building,” in full.

This method includes:

  1. Android Open Source Project as a basis
  2. Additional proprietary files for the hammerhead, to enable GPS, comms, etc.
  3. Additional proprietary files to support the Google Apps suite (Play store, GMail, et al.)
  4. In-tree kernel build from source

Obtain the AOSP Sources

The Android page on Codenames, Tags, and Build Numbers tells us to use the android-4.4_r1 tag for the Hammerhead. (Note: when this page was originally authored, that page was known as “Building for Devices,” which is no longer active. I have updated the link.) Incidentally, as per the Google release notification, this is the same baseline used for the KRT16M factory image.

This procedure is well documented:

repo init \
    -u \
    -b android-4.4_r1
repo sync

Obtain the Vendor Proprietary Files

There are a few methods to do this, but the (at face value) easiest is to download the vendor files from the Nexus Device Binaries page.

wget "$url_base"/broadcom-hammerhead-krt16m-bf9b8548.tgz
wget "$url_base"/lge-hammerhead-krt16m-0efa9c33.tgz
wget "$url_base"/qcom-hammerhead-krt16m-53cf1896.tgz

Now, untar the packages, and run the extractor scripts:

for f in *.tgz; do tar xzf $f; done
for extractor_script in *.sh; do bash $extractor_script; done

After you go through the EULAs and type “I ACCEPT”, once for each extractor, you’ll have directory trees at vendor/broadcom/hammerhead, vendor/lge/hammerhead, vendor/qcom/hammerhead.

Now, in the past, these proprietary binary releases have been fairly comprehensive. Unfortunately, the LG and Qualcomm drops appear to be missing some critial files. (Take my word for it — you won’t have 3G / cellular connectivity.)

If you look at proprietary-blobs.txt and vendor_owner_info.txt (both in the device/lge/hammerhead project), you’ll see that the following files are mentioned, but are not present at this point in the vendor trees.

Missing from vendor/lge/hammerhead:


And these, from vendor/qcom/hammerhead:


Note: actually, OmaDmclient.apk is probably the only one that has to do with cellular networks. (See OMA DM description.)

So, to fix this, we need to do two things:

  1. Obtain the binaries;
  2. Add them to the build system.

For the first, it is possible to rip the binaries from the KRT16M factory image. To do this, you can either simply pull them from a working (stock) hammerhead device, as mentioned here — or, you can rip them from the Factory image file directly. The second method is clearly more repeatably correct, so let’s go that route.

Get the factory image release and untar it:

tar xzf hammerhead-krt16m-factory-bd9c39de.tgz
cd hammerhead-krt16m

Decompress that actual phone image:


At this point, you will see the system partition, system.img. To convert it to something mountable, you need to run it through the simg2img tool that is built with AOSP by default. (When you build android, it shows up at $TOP/out/host/linux-x86/bin/simg2img):

simg2img system.img system.img.raw

Now, mount the thing:

mount -oloop -t ext4 system.img.raw /mnt

From here, you’ll have to copy the files listed above, from the /mnt, into your build tree. There’s undoubtedly countless ways to do that, but I suggest something like this:

for file in $lge_missing_files; do
    mnt_location=$(find /mnt -name $(basename $file))
    cp $mnt_location vendor/lge/hammerhead/proprietary/

And then likewise for the Qualcomm files, replacing lge for qcom.

ALRIGHT. So once we have obtained the files, we need to add them to the build system.

To do this, you need to add PRODUCT_COPY_FILES rules for each of these additional files, so that they get included in the eventual Android phone image. An example of that is shown here, in my github project for vendor/lge/hammerhead, and here, for vendor/qcom/hammerhead.

Note that if you don’t feel like going through all of this BS, you could of course just checkout and use these projects, in lieu of running the extractor scripts for LG and Qualcomm:

rm -r -f vendor/lge/hammerhead vendor/qcom/hammerhead

git clone \
git clone \

The last, and critical step, is to modify the device project, so that these vendor files are used (ref: git commit):

sed -i \
    '/^PRODUCT_RESTRICT_VENDOR_FILES/s/true/false/' \

Obtain the Google Proprietary Apps

Now, usually, RootzWiki posts the Google Apps update packages here, and with a little finagling, you can adapt the updater-script into makefile rules for the Android Build System. Unfortunately, at time of writing, RootzWiki has not provided an update package for KitKat.

The most mature bundling of the Google Apps I have found for Kit Kat so far is from the Paranoid Andorid crew, as mentioned on this post.

The creation of my vendor/google/gapps project from this file is sort of outside the scope of this page, but I will mention a few of the main points.

Inspiration was taken from jpuderer‘s vendor-aospplus project.

Module rules and product copy file rules were created from scratch, for each of the proprietary files found in the Paranoid Android package.

These rules were further developed to include packages like Chrome, and to override packages that are included in AOSP but not in the default factory image. (A very noticable example is that the new Google Home launcher overrides the old Launcher3.)

In short, to include the Google apps, you need to checkout this project:

mkdir -p vendor/google
git clone \

And add rules to vendor/lge/hammerhead, so that the makefiles get included in the build:

cat >> vendor/lge/hammerhead/ <<- EOF 
-include vendor/google/gapps/

cat >> vendor/lge/hammerhead/ <<- EOF 
$(call inherit-product-if-exists, vendor/google/gapps/

(Ref: github commit.)

Including the Kernel Sources

By default, the AOSP image for hammerhead uses a prebuilt kernel binary, specifically device/lge/hammerhead-kernel/zImage-dtb. In order to build the kernel from source, we need to do a few things:

  1. Get the correct version of the kernel source;
  2. Adapt the for an in-tree build;
  3. Adapt the device/lge/hammerhead project, to include the new kernel.

At time of writing, the Android documentation on Building Kernels has not been updated with instructions for hammerhead. However, it’s very similar to the Nexus 4 (mako) procedure.

Get the source by:

git clone \ \
    -b android-msm-hammerhead-3.4-kk-r1 \

You can verify that the commit that branch points to is the same as the stock kernel.

Now, make a few tweaks to fix the kernel build:

# The build fails if we try to make the modules, so remove those lines:
sed -i '48,51d' kernel/

# Build a dtb kernel, not the default zImage:
sed -i '47s,$, zImage-dtb,' kernel/

Finally, we need to modify the device project.

This is a bit more involved, but you can see the patch needed in my github project.

Just Build the Thing ™

Alright. All that above was stuff I had to do. But if you had to do it everytime, you’d probably put a shotgun to your face. Fortunately, I’ve uploaded all the miscellaneous bits and pieces to github repositories, and linked them all together with my own manifest.

In short, just grab the working tree by doing this:

repo init \
    -u git:// \
    -b android-4.4_r1.1
repo sync

So, you can just do that instead.

All you need to do now is build the tree:

. build/
lunch aosp_hammerhead-userdebug
make clean
make updatepackage # -j10

Deploy the thing

After the build (successfully) completes, you’ll be left with an update image package here:


Make sure your hammerhead device has USB debugging enabled. (If you need help with this, YouTube can help. Like This video.)

Enter the bootloader and unlock the device:

adb reboot-bootloader
fastboot oem unlock

Lastly, flash the device, and reboot it:

fastboot -w update $UPDATE_PACKAGE
fastboot continue


Technically speaking, android-4.4_r1 (KRT16M) is the documented tag for hammerhead, while I have used android-4.4_r1.1 (KRT16O), here. As per the Google release announcement, the only difference is that this release includes also support for the Nexus 4, Nexus 7, and Nexus 10. So, it’s more convenient to use that tag, if you’re ultimately supporting the full range of devices.

89 responses to “Howto Build Android KitKat (4.4) for the Google Nexus 5”

  1. Dirk says:


    Thank you very much for this detailed description on how to build AOSP. I will try it right after writing this comment 🙂

    I had only limited success myself in building AOSP for the Nexus 5. I managed to include the proprietary drivers to make GPS and GSM/UMTS work. But after installing the Gapps of from various sources I never got the network positioning to run. Only GPS. And my other problem was that my 32GB Nexus 5 was only recognized as a 16GB Nexus 5.

    I hope your tips on including the gapps within the build will solve my first problem, but do you happen to know how I have to specify that I have a 32GB Nexus 5?


  2. Wayne says:

    Thanks for this info. I was perplexed by the fact that I could not get an AOSP build to work correctly.

    Now that 4.4.2 is out, I imagine some things are different. Looking forward to an updated git to make this easier.


  3. Jameson says:

    @Wayne — the process was similar enough I didn’t bother typing out another blog about it, but I have uploaded the working manifest to github. Try:

    repo init -u git:// -b android-4.4.2_r1
    repo sync

  4. Lakshmana says:

    Thanks f Jameson for the elaborated details, have followed the same procedure for NEXUS4 (Instead of hammerhead Mako is used) also. It worked well for me.

  5. Lakshmana says:

    NEXUS4 image is built with below details , but procedure is of above description

    I have used the Android Branch KOT49H android-4.4.2_r1
    Have used the google apps from NEXUS5 details
    (git clone vendor/google/gapps)

    But there is one problem I have observed is ” unfortunately qulcomm timeservie is stopped” message came randomly twice while using the phone.

  6. Wayne says:

    I finally got some time to try this out for 4.4.2. I still get a system.img that won’t make phone calls. Nothing in the mobile settings, no APNs. Can’t add APNs. Everything else seems fine. I played around trying to add things (via recovery) from the factory image that seemed to be missing from the one built from source, but nothing worked.

  7. Jameson says:

    @Lakshmana — you are right, TimeService.apk is a device-dependent file, from Qualcomm. There should be two independent versions in vendor/qcom/hammerhead and vendor/qcom/mako, instead of only one in vendor/google/gapps. Since I am only working with the Hammerhead at this point, the version in that project is that one.

  8. Jameson says:

    @Wayne I think /system/app/OmaDmclient.apk is the critical one for cell provisioning. Do you have that?

  9. Wayne says:

    Yes,it’s there.

    Is a data wipe required? I just flashed the system and boot images in an attempt to keep my data partition intact; I’m thinking that the app data may be incompatible with the slightly different versions.

  10. Lakshmana says:

    Thanks for the detail Jameson, is there any other way to get the TimeService.apk of mako.

  11. Jameson says:

    @Lakshmana — Sure, you could extract it from the factory image. The method for that is discussed in this blog.

  12. Jameson says:

    @Wayne — I’m not sure, but yes, I do wipe the data partition when switching between factory and one of these.

  13. Wayne says:

    The data wipe is apparently necessary. Doing that gives me a phone that actually works as a phone.

    Still, there are a lot of differences in the factory image and AOSP–even with your patches. The camera is obviously different, but I haven’t dug much deeper.

    I’m disappointed in that I bought a N5 to get away from all the proprietary BS, but it appears it’s a lot more difficult than I thought to have a truly open source phone.

  14. Lakshmana says:

    Thanks Jameson, I have extracted it from google factory image and it worked like charm.
    One more update from my side
    with out google apps, I have built the apps from AOSP code and made them up on MAKO. other vendor binaries are taken as usual

  15. Dejan says:

    Thanks Jameson for these instructions. However, following your steps to build a kernel sources the build fails with following error message:
    *** No rule to make target `zImage-dtb’, needed by `out/target/product/hammerhead/obj/KERNEL_OBJ/arch/arm/boot/zImage’. Stop.
    I updated all makefiles according to the steps you described above. Do you have any idea what’s going on?

  16. Jameson says:

    @Dejan — oops, you’re right. The sed lines in this post were incorrect, the line numbers were off by one. I have corrected the post above. The correct lines would be:

    sed -i '48,51d' kernel/
    sed -i '47s,$, zImage-dtb,' kernel/

    You can also simply view or pull the patch from my kernel project on github. That patch has been correct.

  17. Nathan_OR says:

    Using the -b android-4.4.2_r1 version, I get the following build error:

    “HOSTCC scripts/mod/mk_elfconfig
    /Volumes/android/jameswilliams-android-4.4.2_r1/kernel/scripts/mod/mk_elfconfig.c:4:10: fatal error:
    ‘elf.h’ file not found
    #include ”

    There were no errors reported during the repo sync. Any suggestions?

    Thanks for the very helpful blog!


  18. Jameson says:

    @Nathan_OR — /Volumes looks like you’re on a Mac? Since I don’t use Mac, I do not actually know if it can get the ELF headers or if there’s a tool chain you can use to create ELF binaries. Normally on Linux, the header you mention lives in one of these places:

    jameson@apricot:~$ find /usr/include/ -name "elf.h"

    I guess since the error you get is during kernel build, it’s looking for linux/elf.h.

    I don’t believe Mac OS X is a supported build environment for Android, but maybe it is possible to get working. Similarly, I have no experience cross compiling Linux kernels on Mac hosts for Android targets.

  19. Nathan_OR says:

    Thanks for the reply! According to the directions, Mac OS X is a supported environment for AOSP. Furthermore, I can successfully build the android-4.4.2_r1 branch of the AOSP repo and run it on my Nexus 5. I do believe however that the default AOSP config for aosp_hammerhead-userdebug includes a pre-built kernel image, so this may be the difference. I also found someone else on stackoverflow having the same issue, and like me, he was able to work around the elf.h issue and just ran into another issue. So I was hoping I made some sort of repo or git mistake, but it just looks like some of the stuff in your repo is not Mac OS X compatible.

    If I find a workaround I’ll post back. I may try to re-create your same repo step-by-step, since I really need 4.4 with full google apps, etc.


  20. Nathan_OR says:

    I re-init’d and re-sync’d the android-4.4.2_r1 branch of your repo, and then I copied the elf.h file from /external/elfutils/libelf/ to my /usr/include dir:

    $ sudo cp -a /Volumes/android/external/elfutils/libelf/elf.h /usr/include

    This time, the build completed successfully!

    On to testing the build… thanks again.

  21. abhishek says:

    thanks, with help of this blog i have successfully compiled for my nexus 5.
    thanks again 🙂

  22. Nathan_OR says:

    One more note: the update package filename was slightly different than in your instructions above:


    is what my Mac OS X v10.8 built with your android-4.4.2_r1 branch.

    Again, thanks for taking the time to put this together and write it up!!

  23. Walter says:

    First, thank you for the great post! I’m currently having trouble with mobile data not working using Sprint as my carrier. I built the 4.4.2_r1 branch from the custom repo using Ubuntu 12.04 with no issues during build. Also, the carrier menu settings aren’t doing anything which is probably related. Any thoughts on how to debug my problem?

  24. Jameson says:

    @Walter: I have no idea really, but this might help: . The update zip contains a modified apns-conf.xml, that is reported to help some Sprint users.

  25. abhishek says:

    i have a problem after building ROM. i tried to encrypt phone. it freeze after showing the android encrption logo and no progress bar. i tried with stock ROM. its workign fine with it. can you guide me what may be the cause??

    thanks in advance.

  26. Jameson says:

    @Abhishek no idea — haven’t tried the feature. Feel free to post back if you hunt down a solution.

  27. abhishek says:

    aahhh!! i was using it with multiROM. and this was installed as secondary ROM. MultiROM have problems if you want to encrypt. its an open issue on multiROM github.
    I installed compiled ROM as only ROM than encryption worked fine.
    So, AOSP build is working fine.

  28. biswa says:

    HI Jameson,

    How to add updatepackage target to makefile. Now it throws error saing no target.


  29. val says:

    getting this error when trying to build for hammerhead nexus 5 can you help me please?

    cp: missing destination file operand after ‘out/target/product/hammerhead/kernel’
    Try ‘cp –help’ for more information.
    make: *** [out/target/product/hammerhead/kernel] Error 1

    i have added the commits like you said to and device/lge/hammerhead!!

  30. Jameson says:

    @Val: For whatever reason, your build appears not to be generating the kernel. Are you sure that you have faithfully reproduced the patch to the device project, either via a git pull, or other method? Also — look back in your build log, is there any error indicating that the kernel build has either (1) not happened, or; (2) failed?

  31. Jameson says:

    @Biswa: updatepackage target is defined here: . It should be available by default. Please verify that you have successfully setup the build environment and source tree.

  32. […] i’m building my own Nexus 5 ROM from AOSP following this guide: Which has worked fine, except I want to get it to build to the ‘User’ buildtype rather […]

  33. val says:

    Jameson. yes sir i downloaded your source and copy/paste your commits over using beyond compare. im having a hard time figuring this out and no its not generating the kernel cause it stops almost before it gets started! one question where do you have your kernel? mine is in the sorce tree under kernel/lge/hammerhead?

  34. val says:

    ok finally figured it out i renamed my kernel dir to just “kernel” and seems to be building now! thanks for the write up!

  35. Jameson says:

    @Val: Ah okay, that makes sense. The directory path to ./kernel is hardcoded in, and in the device/lge/hammerhead changes.

    If you wish to put it in another location, you could consider employing a patch such as this: .

    Additionally,you’d need to change the KERNEL_DIR variable in .

  36. val says:

    well it built with no errors this time but it would not boot. couldnt get it to get past google screen! owell will use stock kernel. thanks for the info tho.

  37. Hu Yugui says:

    Thanks for jameson, I can download image to N5, but I download boot.img to N5, N5 can’t bootup.

    I find boot.img use zImage, so change it to zImage-dtb
    Add patch to build Nexus 5 kernel image:

    diff –git a/ b/
    index b7d351e..bea3569 100644
    — a/
    +++ b/
    @@ -5,7 +5,7 @@ ifeq ($(TARGET_PREBUILT_KERNEL),)

    KERNEL_CONFIG := $(KERNEL_OUT)/.config
    -TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
    +TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb

  38. Jameson says:

    @Hu: yes, very true. My sed commands above should accomplish that change; but it is also included in my kernel_msm project, more explicitly as a patch:

    It is essentially what you have, but I have also removed the make lines related to modules, which broke the build, for me, when building in-tree.

  39. Paschalis says:

    Hi guys,
    thanks for the guide!

    It was very helpful!
    I ‘ve compiled AOSP + binaries (not kernel, I just left it with the prebuild binary), on mac OSX Mavericks!

    Everything works except camera.
    It is blank. I downloaded the camera apk, and replaced it under /system/app but nothing!
    Also I have tried with thirdy part app, but still nothing!
    It just freezes!

    Any suggestions?

    Thanks again!

  40. Pradeep VR says:

    Hi Jameson, am building KitKat for learning purpose and followed instructions given here

    After downloading source code, below were the instructions executed in my source directory :

    source build/
    lunch aosp_arm-eng
    make -j4

    and am getting below error with build failing:
    make: *** No rule to make target `external/wpa_supplicant_8/wpa_supplicant/src/drivers/’. Stop.


  41. How to I produce a recovery flashable zip instead of a fastboot flashable zip? Thanks a lot for this guide. Its the only reliable one I’ve found

  42. Jameson says:

    @Digitalunderground.Xda: Check out the contents of ./build/core/Makefile. There are a couple of other build targets that might of interest to you; among them are recoveryimage and otapackage .

  43. Corey says:

    Thanks so much for the Google apps bundle! Worked like a charm for me yesterday.

  44. jwstyle says:

    Thank you so much!!!!

  45. Brajesh Sharma says:

    Great guide. Can you also make a guide on cherry-picking?

    I mean a lot of people including me doesn’t simply want to build aosp roms, they want to add features to it according to their needs. They can do the same by cherry-picking from different popular roms like cyanogen, pa, slim etc.

    There is no guide such like that on internet (based on my searches on google). If you get time, I would request you to make a guide (which I know you can) which covers the above thing. I understand how to cherry-pick but I am mostly stuck with maintaing those on github.

  46. Brajesh Sharma says:

    @Digitalunderground.Xda : make -j3 otapackage
    j3 cuz I have a 2 cores of processor, you can adjust as per your configuration.

  47. baggz143 says:

    I love your guide. Better than all the other guides on xda for sure. I would love if you could make a small guide on baking superuser to the build after building it 🙂

    Thank you again.

  48. Frank says:

    Really appreciate this guide. It is better than the guide on the Android official website. Many thanks!

  49. baggz143 says:

    One question to nosemaj and dirk the first post at top.

    I had issues with gps and time before reading this awesome guide. and now everything works but no network positioning as mentioned at the first post. Any one else having this or dirk found a solution to fix that?


  50. Bhavani Prasad says:

    I am trying to localize strings for the default apps in nexus 5.
    When I have added the values-bn/strings.xml with bengali strings in all the system apps, Its not getting included in the APK and the localization strings not reflected in device too.

    Appreciate if any one can help on this.

    Thanks in advance

  51. Cheng Yang says:

    what’s the purpose of build kernel from source instead of use prebuild?

  52. Jameson says:

    @Chen Yang — the kernel is simply another software package that comprises the overall Android operating system. If you do not have need to modify its source or build, it is true that it will only add to an already lengthy compile time. In this case, you could safely and effectively use the prebuilt kernel.

  53. Peter says:

    Thanks for the guide

    I am getting following error

    Syncing work tree: 68% (281/412) fatal: reference is not a tree: 52ac2e02815ccf6e66ea980a8aaec6a70a2a4fe8

    kernel/: leaving android-msm-hammerhead-3.4-kk-r1; does not track upstream
    error: kernel/: kernel_msm checkout 52ac2e02815ccf6e66ea980a8aaec6a70a2a4fe8

    I’ve repo sync way too many times, is this something

    Then during make clean I get following erro

    Checking build tools versions…
    You are attempting to build with the incorrect version
    of java.

    Your version is: java version “1.7.0_55”.
    The correct version is: Java SE 1.6.

    Please follow the machine setup instructions at

  54. Peter says:

    I also ended up with 10 errors

    10 warnings generated.
    SHIPPED scripts/kconfig/
    SHIPPED scripts/kconfig/zconf.lex.c
    SHIPPED scripts/kconfig/zconf.hash.c
    HOSTCC scripts/kconfig/
    HOSTLD scripts/kconfig/conf
    init/Kconfig:389: can’t open file “kernel/irq/Kconfig”
    make[3]: *** [hammerhead_defconfig] Error 1
    make[2]: *** [hammerhead_defconfig] Error 2
    make[1]: *** [sub-make] Error 2
    make: *** [out/target/product/hammerhead/obj/KERNEL_OBJ/.config] Error 2

    which can not give me a final ROM

    Let me know if you ran into similar issues before

  55. Jameson says:

    @ Peter — I’m not sure exactly how you’ve arrived at that, but you might want to check your repo init command.

    If you’re using my manifest, then there is no ref for android-msm-hammerhead-3.4-kk-r1 . Commit 52ac2e02815ccf6e66ea980a8aaec6a70a2a4fe8 lives in a branch called android-4.4_r1.1 as you can see here: .

    For the latest version of Android, try this:

    repo init -u git:// -b android-4.4.2_r1
    repo sync

    If one of those steps fail, then definitely don’t try and build. It obviously won’t work.

  56. McNeil says:

    @Jameson, first off thank you for taking the time and effort to provide a tutorial like this. I’m having an issue that I hope you might help with. Everything builds just fine using make -j12 updatepackage. The only thing is that I don’t have root or busybox installed, so I run the $OUT/.img files through ArchiKitchen to add root and busybox. Archikitchen then packages everything up into a flashable zip. After flashing the zip, I don’t get phone service, nor can I provision any APN’s. Ultimately what I’m trying to do is have root/busybox built in without having to install them post flash. Obviously, the kitchen is doing something to mess with the provisioning of the phone. Any ideas? Thanks in advance.


  57. McNeil says:

    @Jameson, fyi, I was able to resolve the APN issue. The kitchen was doing something that messed up the build. Probably user error. I was also able to solve the issue of building in Superuser and Busybox into the source. The only issue I have now is with GPS/location services and the fact that my apps from the PlayStore won’t automatically download. With GPS, I have an app that automatically detects my location when using other ROM’s. Now I get “We cannot determine your location. Either your GPS is disabled or your current location is temporarily unavailable”.



  58. priyank says:

    Thanks for the above article,I could successfully build image for 4.4.2 but I am facing some problem with current location detection even with Google maps.Everything seems to be working fine apart from location reporting features. The device could not detect current location. But if I flash device with factory image, location reporting features is working fine.Any ideas?
    Thanks in advance.


  59. Wayne says:

    @Bhavani Prasad. I had this problem too. You need to add a line to [aosp_home]/frameworks/base/core/res/res/values/config.xml

    at line 773:

    Add this line:

    So now it looks like this:

    Recompile and install (or just replace framework-res.apk).

  60. Wayne says:

    The XML tags seemed to have confused the comment text. Is there a way to add comments with XML tags?

  61. […] Howto Build Android KitKat (4.4) for the Google Nexus 5 […]

  62. Pietro says:

    Thanks for the blog !
    I have repo sync your latest android kitkat:

    repo init -u git:// -b android-4.4.2_r1
    repo sync

    and tried to build :

    . build/
    lunch aosp_hammerhead-userdebug
    make updatepackage

    I am running on Ubuntu 14.04 with java version “1.6.0_45”
    However, I get these 2 errors (and also 6 other warnings):

    —– Made recovery image: out/target/product/hammerhead/recovery.img ——–
    Compiling SDK Stubs: out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/classes.jar
    out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/telephony/gsm/ modifier static not allowed here
    public static class SmsManager
    out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/android/telephony/gsm/ modifier static not allowed here
    public static class SmsMessage

    Any idea why?


  63. Jinghao says:

    Thanks Jameson for this awesome post. I’ve successfully compile AOSP 4.4.4 on Nexus 5, and here is the vendor blobs repo I used. Data connection of Sprint is also fixed by the apn-conf.xml from the xda forum.

  64. Jameson says:

    @Jinghao — Awesome! glad it was helpful. 🙂

  65. Jinghao says:

    For kernel building, we also need to change definition of TARGET_PREBUILT_INT_KERNEL, so that zImage-dtb get copied, instead of zImage.

    -TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage
    +TARGET_PREBUILT_INT_KERNEL := $(KERNEL_OUT)/arch/arm/boot/zImage-dtb

  66. Alex says:

    Thanks Jameson for this very useful info

    I’ve faced very interesting issue hope you can share your thoughts

    Build: kitkat 4.4 KRT16M
    Vendor files taken from Google resources; plus all missed files from lge and qcom including libv*.so, TimeService.apk and etc.

    Build seems working fine on 3G; however not able to sync time over NITZ:
    E/SystemClock( 1165): Unable to set RTC
    E/SystemClock( 1165): java.lang.SecurityException: setTime: Neither user 1001 nor current process has android.permission.SET_TIME.
    E/SystemClock( 1165): at android.os.Parcel.readException(
    E/SystemClock( 1165): at android.os.Parcel.readException(
    E/SystemClock( 1165): at$Stub$Proxy.setTime(
    E/SystemClock( 1165): at android.os.SystemClock.setCurrentTimeMillis(
    E/SystemClock( 1165): at
    E/SystemClock( 1165): at

    I’ve tried to re-sign TimeService.apk with platform key which I took from /build/target/product/security – no effect.

    Have you seen NITZ sync issues on your builds? Thanks in advance.

  67. Keith says:

    Just wanted to say thank you for writing this guide. I have been trying to build android from source, I have been mostly successful but your guide definitely filled in some holes.

    The scripts you include I found especially helpful – it also prompted me to look further into linux and how to write my own scripts. Still looking for a good guide on that, I found a few but they are a little overwhelming..

    Anyways thanks again.

  68. Charles Marslett says:

    I am just starting building an Android KitKat. And I have run into an issue: the initial download into the .repo tree is 25GB and the checkout for “-b android-4.4_r1” takes another 8.5GB. The Android documentation says you need 8.5 GB for the source download (so they leave off the .repo tree, I’d guess).

    That means you probably need more like 55-60GB to do your first build. That surprised me and blew away my prepartions. I am going to get another 1 TB drive set up to finish my first build.

  69. Charles Marslett says:

    Otherwise, I should say this is the best guide I have found after a lot of searching!

  70. Pavel says:

    Wow it is a great manual, thanks 🙂

    I followed the entire step and flashed the images to my Nexus 5 deives. Unfortunately where never I’m trying to activate the diag mode (setprop sys.usb.config diag,adb) the device is losing connection with adb and finally crashing. Are you familiar with such a problem?

  71. Android7 says:

    Thank Jameson for this great blog post.
    I have successfully built 4.4.4_r1 following this method. However, I am still using google apps from your git repository.

    I have tried taking the latest paranoid android stock google apps (2014/8/11 version) linked below, and building a 4.4.4_r1 rom, adding necessary scripts under vendor/google/gapps as you did, but failed so far (Setup Wizard process stops at boot). Did you go through this? If you know how to resolve this issue, I would appreciate if you can share your experience.

  72. Wasif says:

    hello, nice and helpful article,
    i am having the following error while compiling can you please suggest what might be going wrong with this?

    thanks in advance

    Note: Recompile with -Xlint:unchecked for details.
    1 error
    make: *** [out/host/common/obj/JAVA_LIBRARIES/core-hostdex_intermediates/classes-full-debug.jar] Error 41
    libcore/luni/src/main/java/libcore/reflect/ type parameters of A cannot be determined; no unique maximal instance exists for type variable A with upper bounds A,java.lang.annotation.Annotation
    return AnnotationFactory.createAnnotation(annotationClass, members);
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    Note: Some input files use unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error
    make: *** [out/host/common/obj/JAVA_LIBRARIES/core-libart-hostdex_intermediates/classes-full-debug.jar] Error 41

  73. Feng says:

    Hello, I tried with java java c version “1.6.0_32” and it gave me errors.
    OpenJDK Runtime Environment (IcedTea6 1.13.4) (6b32-1.13.4-4ubuntu0.12.04.2)
    OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)

    In file included from external/chromium_org/content/common/android/
    out/target/product/hammerhead/obj/GYP/shared_intermediates/content/jni/HashSet_jni.h:10:26: error: extra tokens at end of #ifndef directive [-Werror]
    out/target/product/hammerhead/obj/GYP/shared_intermediates/content/jni/HashSet_jni.h:11:26: error: missing whitespace after the macro name [-Werror]
    In file included from external/chromium_org/content/common/android/
    out/target/product/hammerhead/obj/GYP/shared_intermediates/content/jni/HashSet_jni.h:24:20: error: expected initializer before ‘<' token
    out/target/product/hammerhead/obj/GYP/shared_intermediates/content/jni/HashSet_jni.h:26:17: error: expected initializer before '<' token
    out/target/product/hammerhead/obj/GYP/shared_intermediates/content/jni/HashSet_jni.h:29:22: error: expected '{' before '<' token
    out/target/product/hammerhead/obj/GYP/shared_intermediates/content/jni/HashSet_jni.h:29:22: error: expected unqualified-id before '<' token
    external/chromium_org/content/common/android/ error: expected '}' at end of input
    cc1plus: all warnings being treated as errors
    make: *** [out/target/product/hammerhead/obj/STATIC_LIBRARIES/content_content_common_gyp_intermediates/content/common/android/hash_set.o] Error 1

    Any suggestion?

  74. Jameson says:

    @Feng — most people use Oracle JDK. Haven’t looked up whether OpenJDK works in a while / I forget.

  75. Suresh Rajashekara says:

    I tried OpenJDK (Ubuntu 12.04) and did not work for me. I ran in to similar errors that Feng did.

    Thanks for the writeup Jameson.

  76. Harish says:

    Dear Jameson,
    I successfully built android 4.4.4 for nexus 5 with your tutorial. now trying the same for moto e
    i had cloned kernel into moto e kernel/moto/condor,
    moto e device git into device/moto/condor,
    moto e vendor git into vendor/moto/condor.
    running source build/
    updated the lunch combo with a new option

    running lunch aosp_condor-userdebug
    resulted in the following errors

    No private recovery resources for TARGET_DEVICE condor
    make: *** No rule to make target `out/target/product/condor/kernel’, needed by `out/target/product/condor/boot.img’. Stop.
    make: *** Waiting for unfinished jobs….

    i think i placed kernel sources at wrong place,
    can you please correct me

  77. […] References: [1] 안드로이드 Full Source 다운로드 및 Build 하기(PDK 환경 구성), [2] Downloading and Building, Android, [3] Binaries for Nexus Devices, Google Developers, [4] Howto Build Android AOSP for Google Nexus 4, [5] Howto Build Android KitKat (4.4) for the Google Nexus 5, […]

  78. know patience says:

    Thanks for this blog post, your contribution has been instrumental in helping me get Lollipop up and running on the N5.

  79. Sean says:

    Thanks for the post. I am building the kernel for a Samsung Note 2, and get the following error:

    WARNING: vmlinux.o(.data+0x8434): Section mismatch in reference from the variable msm_mpm_debug_mask to the function .init.text:mpm_irq_domain_linear_size()
    The variable msm_mpm_debug_mask references
    the function __init mpm_irq_domain_linear_size()
    If the reference is valid then annotate the
    variable with __init* or __refdata (see linux/init.h) or name the variable:
    *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console

    WARNING: vmlinux.o(.data+0x844c): Section mismatch in reference from the variable msm_mpm_debug_mask to the function .init.text:mpm_irq_domain_legacy_size()
    The variable msm_mpm_debug_mask references
    the function __init mpm_irq_domain_legacy_size()
    If the reference is valid then annotate the
    variable with __init* or __refdata (see linux/init.h) or name the variable:
    *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console

    Can you help?

  80. Are parts of this guide still relevent to new builds?

  81. Jameson says:

    Yo — Daniel, I haven’t bothered to build Lollipop, yet, actually! Not doing as much phone stuff these days, I guess. Not sure how much of this is relevant to Android 5, I’d guess a lot of it is. But there’s always some subtle trick/workaround, it seems. Let’s see how bored I get this weekend, maybe I’ll give it a try on my spare Nexus.

  82. Yuan says:

    Hi Jameson,
    Thanks for your guide, I follow the guide for every instruction but after I deployed it on my nexus5 and pressed power button to start my system, the phone just hang on black screen and no response. Do you know what should I do now?

    Thanks a lot.

  83. fireNice says:

    I re-wrote/re-built the tutorial from the top down-just to get things working on my side.. Let me know if you want me to link it. Thanks for the guide

  84. Jameson says:

    @FireNice Sure of course! Post a link.

  85. fireNice says:

    Alright, it might rough around the edges but it gets it done. Open for suggestions, scrutiny, etc.

    Downloading, Building in Ubuntu(VirtualBox) – Nexus 5(Hammerhead) – 5.1.0_r1(AOSP)

    Building Android Kernel for the Nexus 5 — AOSP(5.1)

  86. Ash Charles says:

    Thanks for the article—really informative. A question: as this script is nominally installing files into TARGET_OUT (modules etc.), don’t we need to force system.img to be updated? The dependency on $(PRODUCT_OUT)/kernel will ensure this gets built by the default Android built target but doesn’t force system to be re-packaged. Maybe I’m missing something?

  87. Mayur says:

    Hi Guys,

    Feng, did you got solution to your problem? I’m getting the same problem like you while building.
    can anybody help me on this?


Leave a Reply