[Google Pixel 3a Guides, News, & Discussion] sic0048:
Edit - just an FYI for complete transparency. I have moved from the Pixel 3a XL to the Pixel 6. I no longer own my Pixel 3a XL. While I've been told (thanks @AndDiSa) that the root process for Android 12 is the same as it historically has been, I no longer can test things myself. (The root process for the Pixel 6 is different and more complicated than this phone). If you run into any problems or issues, please post in this thread and someone will hopefully be able to answer them.

I'm assuming you understand how to use ADB on your computer. If you need assistance with installing or using ADB, please refer to this XDA article for more information. However, here are some common issues that people have with ADB if it doesn't work initially for you. 1) Check the Android System Notification that appears in your phone's notifications after you plug in your USB cord. Your phone probably defaults to "No data transfer" and you need to change it to "file transfer" to allow the phone to connect. 2) Make sure you have USB debugging turned on in the Settings/System (advanced)/Developer options. 3) If this is your first time using this phone/computer combination, you will have to accept the connection when it pops up on your phone.

You also need an unlocked bootloader to complete these steps. If you need assistance with unlocking your bootloader, here is decent set of instructions. Those instructions are based on the Pixel 3 phone, but the steps are the same for the 3a devices.

Here are the official Magisk installation instructions. I will walk through them to help everyone understand them. Please note that while TWRP does work with Android 9 (Pie), it does not work currently with Android 10 or 11. If you are still on Pie for some reason you can choose either installation option, but if you have moved to a later Android version, you must use the "Boot Image Patching" installation method.

Custom Recovery Installation Method

- (available for Android Version 9/Pie only because TWRP does not work currently with the Android 10/11)

This is the easier installation method IMHO, but it does require using TWRP. If you don't know how to get TWRP for the Pixel 3a, please refer to the official TWRP for Pixel 3a thread

Step 1 - Download and install the Magisk manager app on your phone. (link to the latest stable version can be found here).

Step 2 - Using the Magisk manager app, select "Install Magisk" and select the "Download Zip Only" option. This simply downloads the installation zip to your phone's download folder. It doesn't attempt to install anything.

Step 3 - Boot into TWRP - (because TWRP is not permanent on the stock Pie OS, we must follow these instructions each time we want to boot into TWRP).

Step 3a - Download the latest TWRP image for the 3a to your computer (not your phone) from the official TWRP for 3a thread.​

Step 3b - Connect to your phone via ADB on your computer. You should see the device listed if you type the command "adb devices".​

Step 3c - Boot your phone into the bootloader (type the command "adb reboot bootloader").​

Step 3d - Boot into TWRP using this command, "fastboot boot twrp-3.x.x-x.img" (where "twrp-3.x.x-x.img" = whatever the name of the TWRP download is). Please note you are not using the "flash" command as we are not permanently installing TWRP.​

Step 4 - Once the device boots into TWRP, select "Install" and then find the Magisk.zip download from step 2. Swipe to confirm the installation

Step 5 - After the installation is complete, simply reboot system.

Step 6 - Enjoy your rooted phone and install any Magisk modules that appeal to you

Step 7 - Be sure to turn off the "Automatic System Updates" setting found in Developer settings (Settings /System (advanced) /Developer Options). This will prevent the phone from automatically installing an OTA update and instead allow you to follow the steps listed under the "Taking an OTA Update" section below

The Boot Image Patching Installation method

- (the only method currently available under Android 10, 11 or 12, but it also works with Pie).

Use this method if you are on Android 10 or 11 or you are on Android 9/Pie but you don't want to or can't use TWRP.

Step 1 - Obtain a stock boot.img file for the OS version/update that you are currently on. The easiest method is probably to download the applicable full stock image directly from Google. Unzip the files and unzip the second folder and you should find the boot.img file inside.

Step 2 - Copy the stock boot.img file to your phone's storage - probably to /sdcard or to /sdcard/downloads

Step 3 - Download and install the Magisk manager app on your phone. (link to the latest version can be found here). If you are early in the Android 12 cycle, you probably need to use a Canary build of Magisk.

Step 4 - Using the Magisk manager app, press "Install --> Install --> Select and Patch a File" - select the stock boot.img file that you put on your phone in step 2.

Step 5 - Magisk will modify the stock boot.img file and create a patched boot image file. It will save this modified file at "sdcard/Download/magisk_patched.img"

Step 6 - Connect to your phone via ADB on your computer. You should see the device listed if you type the command "adb devices".

Step 7 - Copy the patched boot image from your device to your PC and the adb folder. If you can’t find the file on your phone via MTP or Windows Explorer, you can pull the file by typing the command "adb pull /sdcard/Download/magisk_patched.img" - Please note, I would suggest double checking the "file modified date" prior to moving the file. Be sure to only move the file if it was last modified on the date you are doing this. I've had a strange situation before where the newly modified file didn't immediately show up and the file showed a modified date of the previous month. If you flash an old version, your phone will bootloop.

Step 8 - Boot your phone into the bootloader (type the command "adb reboot bootloader").

Step 9 - Flash the patched boot image to your device using this command, "fastboot flash boot magisk_patched.img"

Step 10 - Reboot (using command "fastboot reboot").

Step 11 - Enjoy your rooted phone and install any Magisk modules that appeal to you

Step 12 - Be sure to turn off the "Automatic System Updates" setting found in Developer settings (Settings /System (advanced) /Developer Options). This will prevent the phone from automatically installing an OTA update and instead allow you to follow the steps listed next.......

Taking an OTA update in the future (if you used this method to install Magisk).

Taking OTA updates is very easy with the Pixel devices because of their A/B partition system. It allows us to uninstall Magisk, take the OTA update, and reinstall Magisk - all from the phone and all without rebooting during the process. Here are the offical Magisk OTA instructions. I will go through the steps to help explain them.

Step 1 - In the Magisk manager app: Click “Uninstall” then “restore images”. DO NOT REBOOT or press the reboot button.

Step 2 - Download and install OTA (in your phone's Settings/System/System Update). DO NOT REBOOT or press the reboot button.

Step 3 - Open the Magisk manager app and click “Install” next to Magisk (usually it says "Magisk is up to date") then “Install to second/inactive slot (After OTA)”

Step 4 - Press the Reboot button in Magisk.

That should be all it takes to install an OTA and keep root.

Please note, we are getting reports that users are getting notifications that an OTA update has been installed even when they have "Automatic Updates" turned off. If this happens to you, don't reboot the phone which is suppose to be the final step in the update process. Instead, follow the above instructions on taking an OTA update, but start in step 3. In other words, you shouldn't have to uninstall Magisk because the update has already been installed. All you need to do is install Magisk to the "second/inactive slot (After OTA)”. After completing that step, you can reboot your phone to complete the update process. Be sure to post your experiences in this thread to let us know if this process works or not.

Just remember that many custom parts (like kernels and Magisk modules) may need to be updated to any new OTA version. Please be sure to check out the forums for each custom kernel or module that you may want to install to ensure it has been updated to the lastest OS version. Don't assume anything or you may find yourself in a bootloop.

If you find yourself in a bootloop after upgrading an already rooted phone

If you find yourself in a bootloop after updating to a new OS version and flashing the magisk_modified boot.img again, it is likely due to an installed Magisk module not being compatible with the new update. To uninstall all Magisk modules to fix the bootloop, follow these steps:

Step 1 - Connect your phone to the computer you use ADB on.

Step 2 - In ADB type the command "adb wait-for-device shell magisk --remove-modules"

Step 3 - Start your phone again or wait for it to go through another bootloop cycle.

Step 4 - as soon as ADB is available (which occurs even during a bootloop) the command will activate, the modules will be removed, and the phone will reboot.

If the normal OTA method isn't working - sideload the OTA update

Taking an OTA update should be as easy as the above instructions. However there is another option available to install an OTA update called sideloading. Sometimes the update doesn't appear on the phone in a timely manner and you may want to manually install the update. Other times the OTA update seems to fail for some reason. In the end, you may decide to sideload the OTA instead of trying get it via the update feature on the phone. Surprisingly, it's actually faster to install the update via sideloading than it will be to take the OTA normally. I'll walk through the sideloading steps.....

Optional Step 1 - Uninstall Magisk (so that it restores the stock boot.img). If you find yourself unable to boot into recovery, you will have to restore the stock boot.img. I've run into this issue on a couple Android 10 images, but most do not require this step.

Step 2 - Download to your computer the correct OTA image from here

Step 3 - Connect to your phone via ADB on your computer. You should see the device listed if you type the command "adb devices".

Step 4 - Boot your phone into recovery (type the command "adb reboot recovery").

Step 5 - The phone will have a green android robot with a red sign over it's open access panel. Press the power button and then the volume up button while still holding down the power button.

Step 6 - Select "Apply update from ADB" using the volume buttons to highlight the choice and the power button to select it to enter the sideload mode.

Step 7 - Using your computer, type "adb sideload ota_file.zip" where ota_file.zip is the name of the OTA file you downloaded in step 2.

Step 8 - Once the update finishes, reboot the phone to complete the update process. (See note below about initial boot times).

Step 9 - To obtain root again, please use one of the two root methods listed above

Please note, while the initial boot is usually pretty quick, it can take longer. I've occasionally seen the process take upwards of 20 minutes and longer. I think part of the reason it can take so long is that sometimes it optimizes the apps during this boot process. The more apps you have, the longer the process may take. When you take an regular OTA update, the phone will change to a screen where is specifically tells you it is optimizing the apps and counts up as the apps are optimized to give you status updates. When you use the side-load method, it all happens with just the regular boot animation running and without any status updates. Because of this, it is easy to assume something has gone wrong with the boot process while in fact the phone is working through the process normally. If it isn't boot looping (showing the initial power screen before moving back to the boot animation), everything is fine and you just need be patient and let the phone complete the process.

My rant about using these "Pre-patched Boot image" files

I started this thread during a period of time where there was a another thread on this forum started by pbanj that showed users how to root their phone by using some pre-patched boot image files. This method is not the generally accepted method and while it works, there are major shortcomings with it (see explanation below). Because it was the only root thread available at the time and he only showed the "pre-patched boot image" method, many people blindly followed his directions only to be confused when it came time to update the software on their phones. I wrote this thread in an effort to show people the official Magisk installation method. Pbanj has since updated his thread and it now includes the preferred method as well. With his edits, the two threads are sharing the same information now, although Pbanj thread still offers people the "pre-patched boot image" method (which I don't recommend people using).

EDIT - Yet another thread pushing a pre-patched root method has been started. It suffers the same issues as listed below.

Shortcomings with using the "pre-patched boot image" method.

As I already mentioned, there is a huge shortcoming with using the "pre-patched boot image" method described in the other root thread. Because he provides a pre-patched boot.img file, you skip some normal installation steps. In the end you have the exact same patched file (which is why his method works), but you cripple the system when it comes to taking any future OTA. That's because the first step in taking an OTA update is having Magisk reflash the stock boot.img effectively uninstalling itself. This step fails if you used his pre-patched boot image method because you skip the step where Magisk creates the backup of the stock boot.img that it needs to uninstall itself.

I already used the "pre-patched boot image" method to gain root. What can I do?

First, let me clarify and say that there is nothing wrong with your phone or root privileges. Your phone will work exactly as expected and root and Magisk will work exactly as expected. That being said, in the near future you will want to update your phone to the latest Android update and this is where the "pre-patched boot image" method is much more cumbersome. The best option is to simply undo his root method and re-root using the method described above. To do this, flash the correct stock boot.img file to your boot partition and then follow the steps above to reinstall Magisk. Jbanj has confirmed this method will work. The other option is just wait until you need to take an update and then sideload the OTA update following the instructions above. This will remove root and you can then follow one of the two methods to obtain root as outlined in this thread.

Notes

- Please be sure you are on the latest adb and drivers which can be found here.

- You do not need to keep the stock boot.img file (from step 2 of the Boot Image Patching method) on your phone after completing these steps. Magisk saves the stock boot.img backup at /root/data in a file with the name "stock_boot_XXXXXXXXXXXX.img.gz"

Thanks to.......

@ZVNexus for getting TWRP working on the 3a and 3a XL phones

@topjohnwu for making Magisk what it is today