Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

29 October, 2025

Building Android from Source (AOSP 15) on Lenovo ThinkBook 16p G5 IRX

🚀 Building Android from Source (AOSP 15) on Lenovo ThinkBook 16p G5 IRX

Author: Porfy Vidal
Platform: Ubuntu 22.04 LTS
Target: AOSP 15 (Vanilla Ice Cream, Cuttlefish Emulator)


🧩 1. System Overview

After multiple rebuilds and optimizations, this guide shows the complete setup for a working AOSP 15 development environment on the Lenovo ThinkBook 16p G5 IRX with Ubuntu 22.04.

Key goals:

  • Compile AOSP 15 from source
  • Run Cuttlefish emulator (x86_64 phone)
  • Enable ADB access and app installation
  • Automate system maintenance tasks

⚙️ 2. Preparing Ubuntu 22.04

Install the essentials and developer tools:

sudo apt update && sudo apt install -y \

  openjdk-17-jdk python3 git-core gnupg flex bison gperf build-essential \

  zip curl zlib1g-dev libc6-dev libncurses5-dev libncurses5 \

  x11proto-core-dev libx11-dev libgl1-mesa-dev libxml2-utils xsltproc unzip \

  fontconfig repo ccache

Optional (but useful) developer tools:

sudo apt install -y htop nvtop iotop baobab gnome-disk-utility gparted \

  vim nano gnome-tweaks filezilla qbittorrent chrome-gnome-shell


🧰 3. Set Up the AOSP Source Tree

mkdir ~/aosp15

cd ~/aosp15

repo init -u https://android.googlesource.com/platform/manifest -b aosp-main

To sync specific components only (faster iteration):

repo sync -j1 --fail-fast external/ComputeLibrary external/apache-harmony \

external/aws-sdk-java-v2 prebuilts/remoteexecution-client prebuilts/tools

Expected output:

repo sync has finished successfully.


🧱 4. Build Configuration

cd ~/aosp15

source build/envsetup.sh

Choose the target build:

lunch aosp_cf_x86_64_phone-trunk_staging-userdebug


🖥️ 5. Installing Cuttlefish Emulator Packages

Download the following from the official AOSP Cuttlefish build server:

cvd-host_package.tar.gz

aosp_cf_x86_64_only_phone-img-14253210.zip

Extract them:

mkdir ~/cuttlefish

tar -xzf ~/Downloads/cvd-host_package.tar.gz -C ~/cuttlefish

unzip ~/Downloads/aosp_cf_x86_64_only_phone-img-14253210.zip -d ~/cuttlefish

Verify images exist:

ls ~/cuttlefish | grep img

You should see:

boot.img

init_boot.img

super.img

userdata.img

vendor_boot.img

...


🧪 6. Launching the Emulator

cd ~/cuttlefish/bin

./launch_cvd

Once launched, check ADB connectivity:

adb devices

Expected:

List of devices attached

0.0.0.0:6520	device

Open an interactive shell:

adb shell


📦 7. Installing Apps via ADB

To install an APK:

adb install MyApp.apk

For .xapk packages:

  1. Unzip the .xapk.
  2. Find the contained .apk file.
  3. Install it:
adb install app.apk


🧼 8. System Maintenance Automation

Create /usr/local/bin/sysrefresh to automate updates and cleanup:

#!/bin/bash

echo "============================================="

echo "🕒 System refresh started at: $(date)"

echo "============================================="



echo "🔄 Checking for package updates..."

UPDATES=$(apt list --upgradable 2>/dev/null | grep -v Listing | wc -l)

if [ "$UPDATES" -eq 0 ]; then

  echo "☑️  No updates were needed. System is already up to date."

else

  echo "🛠️  Installing updates..."

  sudo apt update && sudo apt upgrade -y

fi



echo "🧹 Performing cleanup..."

sudo apt autoremove -y

sudo apt autoclean -y



echo "🧠 Disk space usage summary:"

df -h | grep -E '^/dev/nvme|Filesystem'

echo "---------------------------------------------"

echo "✅ Last refresh completed: $(date)"

echo "---------------------------------------------"

echo "🟢 sysrefresh complete."

Make it executable:

sudo chmod +x /usr/local/bin/sysrefresh

Run it any time:

sysrefresh


🖥️ 9. Display Configuration

Switching to Xorg restored full dual-monitor support.

Current setup:

  • Internal display: eDP-1 (3200×2000)
  • External monitor: HDMI-1-0 (3840×2160)

Dual display:

xrandr --output eDP-1 --primary --mode 3200x2000 --pos 0x0

xrandr --output HDMI-1-0 --mode 3840x2160 --right-of eDP-1 --scale 0.5x0.5

External only:

xrandr --output eDP-1 --off --output HDMI-1-0 --auto

Internal only:

xrandr --output HDMI-1-0 --off --output eDP-1 --auto


🧩 10. Summary of Achievements

  • ✅ AOSP 15 environment successfully built
  • ✅ Cuttlefish emulator running smoothly
  • ✅ ADB functional for app install and testing
  • ✅ Automated maintenance script (sysrefresh)
  • ✅ Dual-display working under Xorg
  • ✅ Optimized Ubuntu 22.04 for development

💡 Final Thoughts

This setup transforms the ThinkBook 16p G5 IRX into a powerful Android development workstation. While the process takes patience, once configured, the environment is stable and production-ready.

“Building Android from source isn’t just about compiling code — it’s about understanding the entire ecosystem.”


Guidance provided with the help of ChatGPT (OpenAI) 

Till then!

12 April, 2015

My Dying External HDD... revived – by Ubuntu Linux

Tux, the Linux penguin
Tux, the Linux penguin (Photo credit: Wikipedia)
12-April-2015



In my years of computing, the volume of data that I have to keep grew lineary, sometimes exponentially, downloads here and there, documents piling up from transactions day in and day out. Naturally, an external HDD was required.

I bought a WD 1.5TB size, and it was immediately put to use.

It was big and heavy, and bulky, so when the remaining size in my internal HDD was enough to hold my daily space requirement, then the external HDD was disconnected and kept away.

And that was bad. The storage time was quite long, so by the time I needed to use it again, errors came up. Of course, this was all in Windows.

I tried using chkdsk to fix the error, and with a 1.5TB size, the time it took to repairing entailed long hours, and I had to leave it running overnight, but in the morning, the repair was still not done.

I had to abort, and to some point in time, that helped.

Until Windows had to give up on the chkdsk repair. I mean, today, I tried doing another repair for a very important file that I need, it didn't go through.

So I booted up in Ubuntu Linux, and used GParted to fix and repair the external HDD, and that somehow went through. Most importantly, the drive appeared in the list, and when I clicked on it, the files were shown. Not all of it, but the one I needed, I found, and copied out.

As one forum commentator said, “Way to go!” Reverse-engineer a Windows program and use it in Linux to repair a disk that can't be repaired in Windows! Of course, he is referring to fsck, and another utility.

Anyway, my external HDD is still okay after all, only that it can be accessed through Ubuntu Linux, not through Windows.

I might stick with Ubuntu Linux more often. This article is written and posted using Ubuntu Linux.

Till then!


----------


The passing away of my old desktop PC

Screenshot of the Welcome screen of Ubuntu Des...
Screenshot of the Welcome screen of Ubuntu Desktop 11.04 CD (Photo credit: Wikipedia)

12-April-2015



My old desktop PC died, officially. It was originally installed with Windows XP, but I tried to run in in Vista when the OS was released, then finally to Windows 7. Well, they all run okay, but to say the least, it was slow. And why not? It was an old PC that can only accommodate a maximum of 2GB RAM. 2 slots, that's all.

The longest time possible it was running Windows 7 OS, but when 14.04 Ubuntu was released, I thought, “Why not try and see if Ubuntu Linux will be better?”

I did just that. And it was on dual-boot mode. Windows 7 alongside Ubuntu Linux 14.04.

For some time, I run it that way, and one very stark difference is the speed. Windows 7 was slow, Ubuntu Linux was speedier. And they use the same hardware and all.

About 2 months back, I decided, I am not doing anything in Windows 7, or to say it more specifically, I cannot do anything in Windows 7 because I am simply waiting for a button click to get through, or complete.

Came the decision: Wipe out drive C:, and install Ubuntu Linux – only!

I did just that, and Ubuntu Linux installation started nicely. That was just about the time we were going to have dinner, so I left the old desktop PC alone while the installation was going on.

Afterwards, when I checked on the installation progress, I noticed that the lights on the PC were off. The power switch was still turned on, so I was wondering how it was turned off. I tried to press the power button, but no response. I had to open up the casing to check on what the problem could be.

No power. I did the standard troubleshooting steps, but there isn't anymore a response, like simply leaving the PC unpluged for a while and letting the stored charge be discharged, and upon plugging back in and turning the switch on would immediately turn the blower fan momentarily on, then off – well, none – nada!

A few more rounds of doing this, and with the night getting late, I had to retire, and to 'officially' retire the old desktop PC as well.

Good thing was that the secondary hard disk is still intact, and it is still in the PC today, but before the supposedly installation of Ubuntu Linux, I made it sure that all data was moved out of the primary disk, and all stored in the slave disk.

It has served me a long time, and it had its time. Computers don't live forever. And it picked a fine time to die, just when I thought of giving it a 'new life' with Ubuntu Linux...

Till then!


-----



25 August, 2014

Partitioning, GRUB and Boot-Repair

Tux, the Linux penguin
Tux, the Linux penguin (Photo credit: Wikipedia)
Sunday afternoon, 24-Aug-2014


I was configuring the pagefile.sys partitions in my Windows 8.1 laptop, which is currently also having dual-boot feature – yes, I am running Ubuntu Linux and Windows 8.1 in the same machine, and I am always enamored by the simplicity and ease of use of Linux. But that time I was in Windows, and having read some useful article which tells of how to make pagefile.sys work better, I proceeded to execute the necessary changes.

First point is to use a space in a drive other than where your OS is installed, and better yet, create a partition all for the page file’s use. However, you can’t ever get away from creating a page file in the OS’s same drive – this has its own use. So now, you need to have 2 partitions for the page file, one in the drive where your OS is installed, and another in a separate drive. How big is the size? This is a big question, and the standard answer is 1.5x your installed RAM size. Not exactly correct, the guy said. Primary use of page file is to move from RAM whatever memory of inactive programs into the page file. So how big is that? Not really big. Minimum? 1GB. Maximum, twice of that. So simple math would yield 2GB. That is all you need. Quite small, eh? Just enough. That is why you need to have the page file in the (usual) installation drive for the OS, which is C: drive, because of error and crashes, when there is no time to reach the other paging file in the other drive. To be convenient, just set aside 4GB to 8GB. How you divide between the 2 partitions, that is entirely up to you.

I thought that I was all set, and proceeded to go and create the partition, so I downloaded and installed EaseUS Partition Master, and get it to work on my requirements. Easily I identified where I would be slicing off the 8GB, and that was divided into 3.5GB from C: drive, and 5GB from P: drive. With the ease of use provided by EaseUS Partition Manager, that was a breeze. Just right-click on the drive, and drag either the bar on the left or on the right, to create a space before or after it. Really, it is all that easy. I clicked on OK, then on Apply, which asked for a restart.

I yielded. And that’s when the problem started.

GRUB failed, and it stopped on a prompt that I have never seen before. And it is indicating something like ‘unrecognized drive’ or ‘unknown drive’. I immediately guessed that it was the newly-partitioned space that is still pending processing. I remembered that it was after P: partition that the \sda14 formatted as EXT4 is located, and that might have impacted GRUB.

I almost panicked. Hey, it is only about 5 months since the last disaster happened – Ubuntu Linux installation was done by mistake, overriding Windows, and fortunately, I was able to recover much of my documents, especially the important ones.

I composed myself for some time, trying to figure out, what happened, and what can be done to do recovery. At least I reasoned to myself that Windows and Linux are still intact, since nothing was done, except that the additional partition may have affected GRUB – I still don’t know why.

And to verify my guess, I turned on my other laptop, thought hard on what I should be searching for, until I typed, ‘how to fix GRUB’. One guide told of doing some manual recovery using a Live Linux stick, which I could say works to a certain degree, but no completely. I got to see GRUB, but not the usual menu, which is supposed to show Windows and Linux. Only Linux shows, and when I selected it, it still didn’t boot up to Ubuntu Linux.

I continued to search for other possible recovery methods, and that is when I saw Boot-Repair – one that you install, and it will do the recovery for you.

I installed it, and run it. First time, I didn’t get it to work; I still wasn’t able to get GRUB boot into Linux.

I did another Linux Live stick session, and this time, using the data from the manual recovery article, which identifies the Linux installation partition, and the GRUB partition (which indicates ‘boot’). I went to the Advanced settings, and assigned the MBR to the partition carrying ‘boot’ ID, run the recovery as provided by Boot Repair apps, and that fixed the problem.

When I did a restart, I see the Windows and Ubuntu choices, and yes, there is another, I guess, from the previous run, where I didn’t specifically indicate the MBR partition. I guess I will look for ways to remove that, so it doesn’t cause any other problem, but point is, my GRUB was repaired, and that only took some time, about one hour or so.

14 July, 2014

Day, Date and Time in Taskbar - Skinny Clock solves that!

Nearly forgot ;) - July 26, 07
Nearly forgot ;) - July 26, 07 (Photo credit: ThrasherDave)
14-July-2014


A couple of weeks ago, I started working (again). And the box that I was given was running Windows XP. Yes, XP, as in XP. And the consolation was, the HDD size was considerable. I mean, compared to my previous company, whose old XP  machines came with a measly 40GB, the old machines in my new company, as I also heard from fellow newcomers, was generous: 250GB.

We all know what XP is, at least compared to Windows 7 and Windows 8. And since I am so used to being 'free' when it comes to computing, I find myself suddenly choked and restricted by the limits set to a normal user.

Nonetheless, I still was able to do some workaround, at least with the date on the PC. I was already getting used to the Linux interface, which I also see in Mac computers, so I was looking for the Day-Date-Time display on the taskbar.

Now, I checked this small requirement of mine, actually, a personal requirement, and of course, there are some answers. And some answers I find quite st**id. As I read it, the one who asked the question already mentioned that his/her taskbar is in the normal one-line mode, and they still would say, "What day-date-time?" And they continue saying '"f you just make your taskbar two lines, then you will see the 'day-date-time' info that you are looking for." I'd like to strangle that person!

I guess if you don't know the answer, then just keep quiet. Please!

Now, some guys know the real answer, and here it is. Use Skinny Clock.

Make it replace the system clock, and you can easily format the Day-Date-Time display to your liking. And as I mentioned, for one like me who has limited access privilege, there is the binary version, which you can download and extract to a folder of your choice, then run it from there. No installation required. And, it works!

Try it. I'm sure you will like it.

Till then!

TestDisk - a utility not for the faint-hearted

testdisk_Linux
testdisk_Linux (Photo credit: ignace72)
14-July-2014


A couple of months back, I made the mistake of installing Ubuntu Linux 14.04 over my Windows OS, and I lost a lot of files! Included in the list are my codes, my life's work of 15 years!

I was frantic to say the least, and I scampered to find the perfect utility that will help me in the file recovery. As suggested, I minimized booting into Ubuntu Linux, so the amount of probably unrecoverable files will be minimized. I understood that, and I heeded that suggestion.

Now, there were several that surfaced, but after trying those that I deemed useful, I ended up with TestDisk. As I found, it is not for the fainthearted. I had to run 3-4x before I finally got the hang of it. And yes, there is a GUI version, but I got  more comfortable with the text-based version. Of course, since what I have as a surviving OS is Linux, it is the Linux version that I was able to run.

Here's a list of what I have noted down, in case somebody would need them, intentionally or not. Some of these are listed as part of the help/instruction list. At any rate, here goes:

Press the corresponding keys, and what happens/effect
P - list files in directory
: - to make a selection
c - current file copy
C - copy selected files/directories
Left arrow key - to go back
Right arrow key - to change directory
. - (select single dot) go to parent directory
.. - (select double dot) move down (right arrow key?)
Shift + C - select device

Where are the copied files?
They are in /dev
Directory structure is retained (if that is ever a bonus!)

Linux Live has a limitation on file size, so copy by folder with about 4GB total size, or less. You may become too excited and just select all directories. Well, the copy function will (seem to) work, but it won't be able to go past the file size limit.

To remove copied files, and prepare for the next batch, type:
rm -rf [xxxxxx]
where [xxxxxx] is your filename (wildcards accepted)
Warning: rm -rf is quite powerful, so use with caution.

To list devices attached to computer, type:
ls -l /media

To copy (from /dev to your removable media/portable HDD), type:
cp -ar /dev/xxx /media/xxx/yyy/zzz

To remove temporary files, type:
1. cd /dev
2. rm -rf xxx

If you encounter input/output error, try below:
1. Exit Terminal where error occurred
2. Unmount affected destination drive (USB, HDD, etc); wait for unmount to properly complete
3. Unplug, then wait for 10 seconds or more
4. Plug back in
5. Reduce copied files


C'est t'out!