This post will walk through building and deploying Android 4.3 (Jelly Bean MR2) for a Nexus 4 device, from upstream sources.
A useful source tree, in practical terms, requires these components:
These four components are not bundled together, and need to be assembled into the Android build system.
First, obtain the AOSP tree:
repo init \ -u https://android.googlesource.com/platform/manifest \ -b android-4.3_r1.1 repo sync -c -d -j10
Now, get the proprietary hardware support files, and install them to the source tree:
cd $ANDROID_BUILD_TOP wget https://dl.google.com/dl/android/aosp/broadcom-mako-jwr66y-137ef66d.tgz wget https://dl.google.com/dl/android/aosp/lge-mako-jwr66y-a85ca75e.tgz wget https://dl.google.com/dl/android/aosp/qcom-mako-jwr66y-a5becaf1.tgz for item in *.tgz; do tar xzvf $item done for item in *.sh; do bash $item done # Manually accept all agreements to expand files into ./vendor tree. rm *.sh *.tgz
Note: probably a good idea to stash these in a/some git repository/ies.
Now, get the kernel. Note that the version in the android-msm-mako-3.4-jb-mr2 branch actually has a display driver bug, and “tears” during scroll, out of box. The solution is to use the same revision as is in the stock kernel image.
git clone https://android.googlesource.com/kernel/msm kernel cd kernel git checkout f43c3d9dd98e351a98bbcccff5933061493f30a4
Alright — but it turns out that the AndroidKernel.mk, the main Makefile for the Android kernel, has some issues. The kernel config has modules disabled, but the makefile tries to build modules. You can comment out the offending lines with this sed command:
sed -i '/\t\+\$(.*module/s/^/#/' kernel/AndroidKernel.mk
There are a couple ways to go about this, but an easy way is to download the proprietary files in a bundle from RootzWiki:
That package is intended to be use as an update.zip through a recovery session, once the phone is all loaded with an image. An alternative is to create Makefiles so that the files get included in the build. The key files are device-partial.mk, and Android.mk.
You can also cheat and just checkout that project, into your tree:
cd $ANDROID_BUILD_TOP mkdir -p vendor/google git clone \ https://github.com/jamesonwilliams/vendor_google_mako \ vendor/google/mako
We now have all of the basic components we need to build, but still have to make a few tweaks to the build system. Firstly, we want to use the files we downloaded to ./vendor, so have to remove the RODUCT_RESTRICT_VENDOR_FILES directive:
sed -i '/PRODUCT_RESTRICT_VENDOR_FILES/s/^/#/' device/lge/mako/full_mako.mk
Similarly, we want to use the kernel source we added to the tree — not the prebuilt kernel image that comes with AOSP. The changes to support this can be viewed in this commit.
Lastly, we need to add a couple of lines so that the Google Apps files are included in the build. Changes to support this can be found in this commit.
Alright. Assuming all of the above was followed carefully, we should be ready to build:
cd $ANDROID_BUILD_TOP . build/envsetup.sh lunch full_mako-user make clean make updatepackage
The update package ends up at
Plug in your Nexus 4, ensure that you are able to do USB Debugging, and run:
adb reboot-bootloader fastboot oem unlock fastboot -w update $OUT/$TARGET_PRODUCT-img-$TARGET_BUILD_VARIANT.$USER.zip
At that point, the phone will reboot, and you’ll be running Android 4.3 on your Nexus 4.
© 2019 nosemaj.org