I did this on my Pixel 2, but unless I’m mistaken you have to unlock the boot loader to do it, leaving your device completely unsecured if someone has physical access to it.
I gave up and got a phone from a manufacturer who provides true 6+ year security support. I was surprised to find that iPhone was essentially the only option.