Guide: How to Get Android (Lineage OS 19.1) Working on Raspberry Pi4, The Non-sighted way
Welcome to my articles once more on the world of Android! I’ve written extensively about my ventures into rom flashing, as well as having published some other related virtual machine projects. In today’s world, flashing your phone comes with greater caveats than ever. Google Pay will get disabled, most apps detect rooting, and on some devices, there’s even physical fuses that get blown when you trip a sensor after unlocking your bootloader. (I’m looking at you, Samsung!) In short, the trend towards flashing, while not dead, has certainly taken a backseat. The community exists, and you are safer to flash older devices that are out of their warranty periods anyway. For these devices, it still provides a road and avenue for staying secure and a bit more up to date. This makes it a good alternative, although the way to flash is still just as much of a patchwork as it has ever been.
With that said, the Raspberry Pi can provide us with a good alternative to doing this in a safe and non-destructive way. That is, if you don’t mind re-writing SD Cards over and over again. Sure beats bricking a phone though, I suppose. Most phones can be restored to stock firmware easily, but on some this can be tricky with less than ideal software in the realm of accessibility. Thinking of tools like the MediaTek Flashing one, and others. They’re OK, if you’re advanced with screen readers you’ll figure it out, but it’s not the greatest. Doing this will still require some terminal work. Keep in mind that we must overcome some limitations as non-sighted users. One of these is enabling Talkback on the Rom image itself in a clean way. The other is ensuring ADB is available at boot.
For this you will need a few things, some are software, some of them are hardware. Let’s go over it!
- An HDMI Cable connected to a monitor or a dummy terminal, at least for the initial phase of recovery. Android recovery will not boot without this. For those using a Pi4, you can disconnect this monitor or cable once you have Talkback running. For pi400, this may still be a requirement at all times, and I recommend the Cable Matters HDMI to VGA adapter from the US Amazon or elsewhere as a suitable option. This is a non-powered VGA adapter which will also give you a 3.5MM jack. Be sure to also pick up a female HDMI to male Micro-HDMI adapter for about six US bucks, which you would require for the Pi’s port. I tested out an Insignia HDMI to VGA adapter, but only got popping sounds out of the audio jack even when I powered it via Micro-USB. Your mileage with different adapters may vary. If you’re stuck with “Waiting for TWRP to start….”, this is also why – be sure to plug in your converter box or tv/ monitor.
- Grab yourself an SD card. I recommend 64 GB, but 32 works fine, even 16. I wouldn’t go lower than 16 since storage space for Android should remain ideal. The Pi 4 does take larger SD cards as well, as I’ve tried a 128 and 256 GB capacity.
- Some way of writing to SD cards with a computer or external SD Card reader.
- A Type-C to Type-C cable. Most folks have this lying around, but ideally it should be of high quality. You will need to plug the Pi directly into your computer, so ensuring it delivers good power draw matters.
- Grab yourself a copy of Rufus, an awesome drive creation tool that’s mostly accessible and usable
- Up-front credits! I did not develop this rom, only contributing here and there on forums to it indirectly. Please do check out the profile of Konsta, the developer of this rom and see his other work. I also recommend you check out the Raspberry Pi 4 page on his site. You will find significant details on these pages, including what works, what doesn’t, status, ETC. I won’t link to a direct download here because that’s a chore to update for me, and it doesn’t link the original source as well. This developer releases roms fairly regularly for the device, perhaps each month or so. The good news? You will be able to update it from recovery yourself when you want and not lose data. Read on to learn more.
- Grab yourself a standalone copy of the Ramdisk file for the Recovery image which we will need to boot into command line and do some initial set up first.
- Visit the APK Mirror page for Google TTS and grab it as a standalone copy.
- Also download Talkback’s latest APK file release.
I think that about covers it! Let’s dive right into the prep work.
Getting warmed up to flash the image
Download the Rufus file and the rom latest copy. Once you have both, you’re good to go. Open Rufus, and be sure to have unzipped the .img file out of the zip file first. We can resize it later, even if the IMG file for now is less than the size of your SD card’s capacity. This is normal. In Rufus, choose the “select” button, which will open up a standard file browser prompt. Navigate to the IMG file’s location, and be sure to choose the correct drive in the dropdown. The drive letters will be shown, which will help.
The write process may take anywhere from 5 to 15 minutes, depending on your SD card’s speed. The main thing is that once it completes, Windows will tell you about the presence of a new Boot drive. This is important, keep the drive letter in mind for later.
But wait, which Lineage do I get?
This guide was written targetting Lineage OS 19.1, which uses Android 12.1. However, a few folks (and I find this true on my Pi400) report that 19.1 does not give them sound output. This is a bit odd, and I can’t pinpoint what’s causing this. The guide will work for older Lineage builds, mostly. The big change has to do with how you enable ADB on older builds, requiring some extra lines if you install Lineage 18.1. This is why the batch file included here later is “mostly” automatic – if you’re planning to try one of the later Lineage roms, it works. For some others, you may need to add a few more lines to the build.prop file. Lineage OS 18.1 is based on Android 11 and was last updated in May.
Post flash process
At this point you have a drive with Lineage on it. Congratulations, this was the most writing-intensive part. For your SD Card, anyway. Not for yourself, perhaps. Buckle up because you have a lot of copying and pasting ahead of you. But you’re probably ready for that.
The main thing now is that we need to swap the ramdisks out. So if you recall that recovery Ramdisk image I linked to earlier, it comes in handy now. There are two ways to do this. The more technical of you dear readers will probably modify config.txt on the boot drive, and swap out the filenames there. You could do this, but you could also rename the existing ramdisk.img file to ramdisk.img.bak, and copy over the new ramdisk.img file I linked to swap out the recovery for initial boot.
This can be risky, so I’m linking you to The smaller Ramdisk file, for LineageOS 19.1 rom targets only Which you can always restore if you messed up in your mind as to which ramdisk file is which. Note that link text. This file may not work with other and older Roms. This is why backing up that ramdisk.img is important, but if all else fails you can use a tool like the 7-zip extractor to open the .img file itself. Inside that IMG, there’s a .fat file which contains the untouched boot partition. Extract the ramdisk.img from there and you have it again, no biggy. There is a ramdisk-recovery.img there, the more curious of you will notice. Also notice the size of that recovery file versus this other one, it’s around 14 MB. To my knowledge, this version of recovery will still not provide you with ADB from the recovery stage itself, which is so important to us here. The more advanced users can also grab Gapps (Google apps) as a flashable zip. You can flash this to your Pi 4 once you’re in recovery, so if you want that addition, be sure to download the right ZIP pertaining to the size and amount of apps you need.
Once you have swapped the Ramdisk, you’re good to plug in the Pi to the computer and work away. Open that floodgate of hacker universe. Be in your creative zone with all the terminal ADB recovery flashing commands. The Pi is your playground, my fellow nerd. The Pi is your playground.
Ok, so we’ve flashed it. It booted up. Now what?
At this point you do need Android Debug Bridge. getting this standalone as a platform-tools installer is now easily done, even from Google. If you plug in the Pi over a Type-C cable with the Micro SD inserted, you should hear a Windows chime letting you know a new device was plugged in. This is great.
If you didn’t hear that, make sure your type-C port can deliver enough power (typically 2.5A for the basics) or use a hub. If the Hub is powered, it may provide extra power to the Pi that your computer cannot.
If you still didn’t hear it, I don’t know what’s wrong. Make sure it’s a Pi4. Konsta also has Roms for older Pi models if you’re interested in them, although this ADB and recovery image files will not work there. You can find older images on the Android File Host profile page I linked above. The recovery image file was taken from the Omni Rom project version which builds from some Lineage-rpi-4 sources. I know the nicer thing with older builds may be that ADB was enabled from boot as unlocked and not needing a vendor key set. This is the big problem, right? Since we don’t have Talkback on this image right now, and no Google TTS, we’re a bit lost. There would be no way to get speech on it.
If you install Gapps, you will already have Talkback and Google TTS included in your package, hopefully. (This is precisely why I don’t advise which type to grab besides the minimal one. Most Gapps images don’t include either and you need a substantial amount of apps or custom scripting to get Talkback and Google TTS in smaller Gapps packages, so you’re on your own there.) Otherwise, you can run AOSP lineage. AOSP lineage is not bad, and you can sideload things on it. Up to you, really.
Either way, open up your ADB shell. We’re going to have to remount System as read and write, then pull the build.prop file from that partition. Once we have pulled Build.prop, we need to modify it a bit to allow debugging. This part of the guide may change, but I’m a bit doubtful. We need to modify one value in build.prop to get ADB to work as non-secure. This can be changed back later, of course, and I highly encourage changing it back as it’s a security risk to leave your ADB open. This may not be as bad over USB, but once you open your Android to a local network, troubles can brew. Like on Halloween! Ha, you didn’t think I would squeeze in one reference in there, did you!
The easy way out, a batch file!
As I was driven to madness having to re-write these commands so often, I decided to write up a batch file that will do the work. Hopefully you have ADB set in your system path (in Environment Variables Control Panel) – most auto-installers of ADB do this for you. So you can run this batch file in the folder you have unpacked the files. Keep in mind that for now it rlies on them being named talkback.apk and googletts.apk. I plan to expand this with more logic so it can find the filenames, as well as skip the section for installing them if a gapps zip file is present. Those are super minor additions, but for now it’s thrown together to write the commands in the below sections for you instead of manual typing. Grab the Pi 4 Android Setup Batch file here to skip some typing from below.
This file, over time, has become much more. It will ask you whether you want to install Google apps from a Zip file.
Getting Google Apps
If you want some Google Apps, MindTheGapps is the one Lineage OS Wiki links to for Google Apps and also includes Talkback. You can Browse the listings of Gapps by the developer here and download the Android 12.1 or whichever Lineage you’re flashing.)
After getting the zip, I tend to rename it to something easier, like gapps.zip, but the nerdy of you reading can use autocompletion to type it. This gives you Basic Google things including the Play Store. the Play Store may require extra set up, associating the ID of your device with Google from your Framework, and there are other guides which cover that process way beter. This may no longer be required if the Pi itself is considered a certified device. Here’s a guide on XDA for how to fix that error if you get it, however, if the PlayStore works fine for you, no need to worry. Mind the Gapps is good if you want the basics, including dialer and Google Search, but none of the other Google apps. It gives you all what you need as a foundation but with less complicated features like in Opengapps. Both are good for different situations.
The manual way, and what the Batch file does
Type these lines:
adb shell twrp remountrw system_root
adb shell twrp mount system_root
This will tell you System is remounted. Next, make sure your prompt is still in the Windows terminal (so your directory, not ADB’s shell.)
Update: We can directly edit build.prop on-device using the Stream Editor command. This works if you are installing Lineage OS 19.1. If 19.1 gives you sound issues with no sound once you enable Talkback, I recommend you try 18.1 instead. Just type this line:
adb shell sed -i ‘s/ro.adb.secure=1/ro.adb.secure=0/’ /system_root/system/build.prop
Reverse the numbers in this command to change this back.
If you’re installing gapps, you will need to do do:
adb shell push gapps.zip /sideload
adb shell twrp install /sideload/gapps.zip
The command will give you some output on the copying.
If you don’t want Google Apps, you will need to manually push Talkback.apk and GoogleTTS.apk into /system_root/system/product/app yourself with adb push. The batch file stores this when it asks. You can also not do this and install both of them into userspace (/data) but keep in mind newer restrictions on Accessibility services could limit you. Installing it into userspace may also not allow it on the lock screen until the encrypted user partition is decrypted.
What about older Lineage builds?
If installing an older build of Lineage, you will need to manually push and pull the build.prop file from the system partition. You can do this quite easily. From your working directory, type:
adb pull /system_root/system/build.prop
and then modify the file with the following changes at the end.
Most older ROM versions may not have this, or may have the USB flag set to none. (Be sure none of these are duplicated in the version you are installing.)
Once you have pulled the file, use NotePad or Notepad++ to edit it. You will get better results if the editor supports Unix-style line endings. Once you’re done, just do
adb push build.prop /system_root/system/build.prop
and you’re done. If you get errors about a read-only filesystem, you need to re-do
adb shell twrp remountrw system_root
The last step really is to resize. If you do an LS command, there’s a .zip file for resizing your partition. It’s a small script that will do the work, so just do
twrp install resize_userdata.zip
to run it. The script may take 10 to 30 seconds, but after you are done, it’s safe to unplug the Pi once waiting a minute. I know, it’s the brutal, hacker way. Don’t worry, you can always get back to your Pi Playground land by switching the Ramdisk, you happy hacker you.
You will need to transfer the SD card to your PC and swap out the files again, or the GPIO pin section of the config.txt if you did this the advanced way. Either way, go back to the smaller 2 MB ram disk. In my batch file, I rename the recovery ramdisk.img to ramdisk_recovery2.img, and rename ramdisk_original.img to ramdisk.img.
Now to run Talkback!
After re-inserting the SD, booting up, you will get ADB again. But things will be a little different. For one, no root access for you. (Not yet, unless you want that!) You’ll notice the $ prompt instead of #. Good.
Wait a few minutes for the caches to build and partitions to initialize.
Now we need to install Talkback, if you didn’t install Mind the Gapps or another Gapps package. If you did, you can skip this step. This is as simple as using adb install (Path-to-APK) and watch it run. Most of the Google TTS and Talkback 64-bit APK files on APKMirror should be compatible. This Lineage build is 64-bit ARM, so when downloading apps, it’s best to grab the most compatible target.
After installed, do a reboot with adb shell reboot. Then you can run this command to enable Talkback:
adb shell settings put secure enabled_accessibility_services com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService
If you want this on Pi400, extra work may be needed
Recently it came to my attention that Pi400 will not output sound for Talkback. This is because the default audio output is set to the 3.5M audio jack, and not an HDMI port. Lucky for us, the batch file I made will ask you if you are on pi400. If you pick that one, extra setprop commands are run after booting. Here they are for you.
adb shell setprop persist.audio.pcm.card 1
adb shell setprop persist.audio.hdmi.device vc4hdmi0
Keep in mind that HDMI0 will be the port closest to your SD slot, not the power connector.
So what’s the Hot tip at the end of this script I’m told about, anyway?
Thanks for asking, curious script runner! You might wonder how to get volume higher on a Pi4 if you don’t have physical volume keys. ADB can take care of this for us. I Found a gist of all Keyevents you can send and that does include volume up and volume down. Just do:
adb shell input keyevent 24
for volume up, or 25 for volume down. I could incorporate this into the batch file, maybe by asking you how many times you wish to raise it and then the command runs. Really simple looping stuff. Maybe that’s a small future to-do item.
And you’re done (hopefully?)
Update: If you don’t hear Talkback at all, perhaps ADB failed at starting it. On Android 12, you are able to press Alt+CTRL +Z from within the Lineage OS Setup Wizard to start it. If in doubt, try this first if even after a reboot you don’t hear any speech.
After this, if sound is set up right, the magical forces of our universe have aligned correctly, you should hear Talkback come on. If not, something else is up. Try a USB soundcard, which Android should snap to when you plug it in.
You can navigate via the keyboard. The ultimate experience is through a USB-powered touch screen, which Android will of course support. Have your fun. And don’t forget to tweet @TamAccess on Twitter (while it’s still here for us) if you have questions.
And if you’re up for the dev talk, I encourage you to contribute on the XDA Developers thread for the ROM.