Android had been working on their phone long before that. There is a story by Richard Hipp the creator of Sqlite who was flown in by Android to help with their sqlite deployements on their phones long before it was public knowledge. He also had been working with Nokia/Ericsson who reigned supreme in cell phone market at that time and according to him what he saw by Android blew him away and knew that other companies were doomed. This was well before the Iphone days, I forget the exact date he mentioned but it was circa mid-2000s. It is clear that Apple and Android had been working on a similar product, apple just got to market first.
It wasn’t several years. The G1 was released just over a year after the first iPhone, not long after the iPhone 3G, and it was roughly equivalent to the 3G.
Here's cnet's review (literally just the first link I pulled from Google).
"But still, the G1 doesn't quite offer the mass appeal and ease of use as the iPhone, so it won't be a good fit for someone making the jump from a regular mobile to their first smartphone."
https://www.cnet.com/reviews/t-mobile-g1-review/
I don’t need to read a review. I owned one when they were launched, while I was working as an iPhoneOS developer. I would spend eight hours a day using an iPhone 3G and the rest of the time using my G1. They were roughly equivalent. The iPhone did some things better, the G1 did some things better. It didn’t take “several years” for Google to be in the same ballpark, they were in the same ballpark from launch, which was fifteen months after the original iPhone launch.