Elon Musk has given the world another reason to believe that Apple (NASDAQ:AAPL) is designing an electric car to compete against his own company, Tesla (NASDAQ:TSLA), at some point in the next five years.

"I think it's great they're [building a car], and I hope it works out," said Musk at Vox Media's Code Conference on Wednesday. "It's just a missed opportunity... They should have embarked on the project sooner."

Musk is right. But the reason Apple should have started sooner isn't because the world needs another quality electric-car manufacturer, which it does. It's instead because Apple desperately needs to diversify away from the iPhone.

Sales of the iPhone fell last quarter for the first time since it was introduced in 2007. Apple sold 51 million of the devices in the three months ended March 26. That's certainly a lot of phones, but it was 16% fewer than it sold in the same period last year.

Data source: Apple's regulatory filings.

To make matters worse, Apple is predicting another decline in the current quarter. This is leading analysts to cut their estimates for its stock. Goldman Sachs did so on Thursday, lowering its 12-month price target for Apple stock from $136 a share to $124.

"We are trimming our Apple estimates to reflect lower growth expectations for the smartphone industry," wrote Goldman's team of analysts. "Our reductions [in iPhone sales] are driven by lower market growth, as well as lower average selling prices on a greater shift from developed to emerging markets."

This is problematic for Apple because two-thirds of its revenue comes from iPhone sales. It sold $234 billion worth of products and services last year, $155 billion of which came from the iPhone.

Data source: Apple's 2015 10-K, page 24.

It's also problematic because none of Apple's other products are in a position to pick up the slack. Sales of iPads fell by 19% in the second quarter compared to the year-ago period. And while Mac sales grew last year by 9%, they're down by 7% through the first half of 2016.

Moreover, even if Mac sales pick up in the third and fourth quarters, it would do little to fill the crater left by waning demand for the iPhone. The year-over-year drop in iPhone sales last quarter added up to $7.4 billion, which is $2.3 billion more than Apple's total quarterly Mac sales.

Apple doesn't just need to find another product that will allow it to offset the decline in iPhone sales, in other words -- it needs a blockbuster that will add tens of billions of dollars a year to the company's coffers every year.

The situation will only get direr by the time an Apple electric car rolls off the assembly line, which Musk believes will be sometime around the year 2020. In addition to the fact that people are keeping their smartphones longer before upgrading to a newer version, the industry is becoming increasingly commoditized.

This is bad news for a company that sells the most expensive smartphone in the market and has become dependent on developing economies like India to power top-line expansion.

The net result is that Apple doesn't have a choice but to make an electric car. It's one of the greatest market opportunities right now, and it may be the only one that's big enough to fill the burgeoning hole in Apple's revenue left from lower iPhone sales.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.