Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. 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!

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

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!

15 May, 2014

MonoDevelop and MVC3, I should be content... for now

MonoDevelopLogo
MonoDevelopLogo (Photo credit: Wikipedia)
14-May-2014

You would notice that I would always date my posts. I should. When I do searching on the web, and I find articles, I would be very happy. Only to find that the articles I initially thought to be the answer to my questions are... well... outdated.

Thus, I always date my posts. For me, and for the one who would find them.

I would have to say again, like the scientist Mr Blue in Hulk movie, that I am usually 'more curious than cautious', and this is where most of my problems in my computer life are coming from, and mostly, for the good. I learn by making (unintentional) mistakes.

It is the same thing when I would say, to answer the question, what is the difference between a fresh graduate and a veteran (let's restrict to software developers), since both of them know how to program?

Debugging. Error prevention. Quick rebound. Composure and calm demeanour.

The veteran has been there, and knows what it is like to have issues and problems, even in the middle of the night, and seeks to resolve them based on knowledge learned from previous encounters.

And this is the years gone past, but for the fresh graduate, are the years before him.

And as for me, I should have been contented with what MonoDevelop has to offer: MVC3. I was forcing MVC4, and trying and following and trying and messing up, until finally, what I (unintentionally) broke was my Windows 8.1 OS.

I was curious. About 4 times already on installing and re-installing Ubuntu Linux, and always picking the option of 'Something else', but I got so curious as to what would happen if I pick 'Reinstall Ubuntu...', and boom!

Anyway, I'm back. I found that HP's recovery discs doesn't work (yap, I ordered them from HP since I haven't burned/created my own recovery discs from the preinstalled data), and even when I was able to download Windows 8.1 ISO images, the OEM Key as extracted from the BIOS info using RWEverything (that is the only tool that can do the BIOS data reading), well, it is not accepted to activate Windows. Crap! I have a valid key, but it is not accepted?!

You know what's the solution? Buy a retail version. Another crap! That would be about USD100+, whereas the recovery discs were a fraction, but also useless!

Pardon my disappointment, but anyway, I found a way to get back my Windows 8.1,and being given a chance to see which files, software and applications are important, I saved what's necessary (TestDisk - the only tool that helped me do the recovery) and discarded the rest. I wish I had everything back, but then again...

For now, I should be content with that MonoDevelop has to offer: MVC3. I will do my learning, and who knows, just one day, MVC4, or even MVC5, will come?

Till then!



Enhanced by Zemanta

02 May, 2014

And to indicate in terminal prompt if I am a root user

Sample of BASH through a shell in GNOME. Scree...
Sample of BASH through a shell in GNOME. Screenshot taken in Arch Linux (Photo credit: Wikipedia)
02-May-2014


I would have to say that knowing that I am a root user, or that I activated my being a root user, at least in the prompt, to be a big help. Fortunately, somebody has already thought of this, and has also done it, and has shared it.

So either you are the root user, or you can switch between a normal user and a root user, it would be very beneficial to know when a user mode or privelege is active and available.

That being said, I searched the web, and I found one that worked.

It is editing .bashrc and appending these:

# Turn the prompt symbol red if the user is root
if [ $(id -u) -eq 0 ];
then # you are root, make the prompt red
    PS1="[\e[01;34m\u @ \h\e[00m]----[\e[01;34m$(pwd)\e[00m]\n\e[01;31m#\e[00m "
else
    PS1="[\e[01;34m\u @ \h\e[00m]----[\e[01;34m$(pwd)\e[00m]\n$ "
fi

So the .bashrc could be in your /home/username directory.

Or when you invoke superuser by sudo -i (or sudo su), it would be in /root directory.

By employing this, I am able to know when I am a normal user, and when I am a super user. It may be what you need, for all I know. Try it!

Here's the reference: Changing behavior of bash prompt when functioning as root

Till then!


Enhanced by Zemanta

Fixing BCM4352 driver in Ubuntu Linux

Broadcom
Broadcom (Photo credit: Wikipedia)
02-May-2014

I needed to reinstall Ubuntu Linux 14.04 Trusty Tahr in my laptop, as the program that I needed to use doesn't run. I believe I messed it up - part of my learning, I would say.

As in my previous installation, the Wireless  Network Adapter wasn't working, and that is the one I had to fix first and foremost.

I searched again, and I don't think I found the same article that I used before, but now, I used one which I followed to the letter, and after reboot, I find that the Wi-Fi connection is still not working.

Since I had to go and send my K1 girl off to school, I shut down the computer. And my wife and I had to go to the grocery to grab some things. A couple of hours, we were back.

Computer Home Business

So now I am on my second time to start the laptop after installation. I tinkled with the system settings, specifically on the profile photo, date and time settings, battery life indicator, etc. When I came to the 'Software & Updates section, I did my usual tinkering, checked the boxes on the Other Software and Updates tabs, and surprisingly, coming to the Additional Drivers tab, there was a choice to use the proprietary driver for the Broadcom wireless network card. That means what I installed was recognized by the system!

So, I have to take note of it now, lest I can't find it again should the need arise - to reinstall once again, or do another box.

Here's the link: Fixing Broadcom BCM43xx cards Ubuntu 10.04 and later

Hope this helps others who would run into the same problem: my machine is HP Envy-15 TS.

Till then!

Enhanced by Zemanta