After building the world’s largest, most popular and most profitable search, Google’s second greatest achievement may be building one of the world’s most popular mobile operating systems, Android.

With the mobile web booming, Android could one day prove to be a very profitable initiative for Google, but ironically it’s already producing a profit for one of Google’s greatest competitors, Microsoft.

Yesterday, Microsoft announced that it had licensed some of its mobile and tablet-related patents to Compal, a Taiwanese company that manufactures a variety of electronics devices, including computers and mobile phones.

The patents licensed implicate functionality in Android, and in a blog post, Microsoft EVP and General Counsel Brad Smith and VP and Deputy General Counsel Horacio Gutierrez boasted that the licensing deal was a notable one for the company:

Today’s announcement marks Microsoft’s ninth Android agreement in the last four months. More important, today’s announcement means that companies accounting for over half of all Android devices have now entered into patent license agreements with Microsoft.

According to Smith and Gutierrez, the patent licensing agreements Microsoft has inked with Android smart phone manufacturers “ensure respect and reasonable compensation for Microsoft’s inventions and patent portfolio. Equally important, they enable licensees to make use of our patented innovations on a long-term and stable basis.” Translation: we’re not patent trolls. But Microsoft does have harsh words for those who are more critical:

…it’s past time to wake up. As Microsoft has entered new markets from the enterprise to the Xbox, we’ve put together comprehensive licensing programs that address not only our own needs but the needs of our customers and partners as well. As our recent agreements clearly show, Android handset manufacturers are now doing the same thing. Ultimately, that’s a good path for everyone.

Needless to say, Google is not exactly thrilled that makers of Android devices are deciding to shell out money to an arch rival like Microsoft so that they can continue manufacturing Android devices without the threat of litigation from one of technology’s largest companies. But given Google’s ongoing battle with Oracle over Java licensing, the search behemoth certainly understands that the stakes are high for its partners. In many cases, it’s easier to license than to duke it out in court.

It shouldn’t be this way. The patent system is a mess, and while patent trolls produce the most ire, companies like Google, Microsoft and Apple aren’t exactly pushing too hard for a legislative clean-up. As much pain as they may inflict on themselves through patents and patent licensing deals, the perceived benefits (eg. ability to defend their turf and inflict harm on competitors) outweigh the pain.

Looking at Microsoft and its Android licensing success, it’s no surprise that Microsoft isn’t too disappointed about the billions it’s paid out in patent licensing fees over the past decade. The patents it does own are not only potential cash cows, they can give the company a way to win in markets that the company loses in.

After all, most of Microsoft’s homegrown mobile initiatives could be labeled failures at worst, and works in progress at best. Yet thanks to the patent portfolio it’s built up over the years, it can cash in on Google’s Android success.

The lesson: for better or worse, for the time being, companies that can afford to build a patent portfolio may have a hard time finding a better investment.