Google Inc.'s attempt to build smartphones in the U.S. is ending almost as soon as it began, the result of weak sales and high costs.

The company's Motorola Mobility handset unit said Friday that it will close a factory in Fort Worth, Texas, by the end of the year.

Motorola, which Google plans to sell, opened the factory in May 2013. A few...