When Western companies moved manufacturing to China, it was all about minimizing costs. China was a developing country with labor costs among the lowest in the world. It also offered massive subsidies and readily turned a blind eye to labor abuse and environmental degradation.

Today, China is the world’s second-largest economy and has ambitions of overtaking the West. Its labor, real-estate, and energy costs have increased so much that they are comparable to those in some parts of the United States. According to Boston Consulting Group, by 2014, China’s manufacturing-cost advantage over the U.S. had shrunk to less than 5 percent. Add to that the intellectual-property theft and unfair trade practices that China has engaged in, and it becomes clear why it makes sense for companies to bring manufacturing back to America.

Doing that is not easy. It is hard to hire the large number of skilled manufacturing workers in the U.S.; intricate supply chains pose barriers; and retooling factories is expensive. But with the trade war that President Trump launched and with the Chinese government’s rigging the deck against foreign companies, businesses may have a strong motivation to bite the bullet and make the investment. The problems they have long had in the U.S. are also now surmountable.

Robots have advanced so far that they can do the work of Chinese workers. Foxconn’s announcement in August 2011 that it would replace a million workers with robots at its Chinese factories never came to fruition, because the robots of that era were not capable of doing fine tasks such as circuit-board assembly and could not work safely alongside human workers. Today, industrial robots can thread a needle and work hand-in-hand with humans. They can do practically every assembly job as well as pack the boxes the goods are shipped in.

Assembling automobiles is one of the hardest of all manufacturing tasks. But with the help of a new generation of robots, Tesla was able to ramp up production at its Fremont, California, factory to produce more than 100,000 cars per quarter. It did this cost effectively in a region that has some of the highest labor costs in the world.

Low-value manufacturing can be moved out of China relatively easily. It’s already being shifted to nearby countries such as Vietnam, Thailand, and Indonesia. The challenge — and the prize — lies in the high-value, high-technology manufacturing such as what Apple does in China for all of its products except the MacBook Pro, manufactured in Austin, Texas.

There is a complex web of supply chains that have developed in China for electronic goods. Products such as the iPhone have hundreds of components, including the display, integrated circuits, optical modules, sensors, and internal memory, which are sourced from suppliers all over the world. Over the past three decades, production of these technologies started moving to China, and many of the key suppliers became closely interconnected. It is not easy to disentangle operations from China’s high-density integrated-circuit ecosystem.

But it is easier than it would have been if Western companies didn’t fear China would steal their intellectual property.

In 2015, according to Seamus Grimes of National University of Ireland and Yutao Sun of Dalian University of China, the supply chain for Apple’s products consisted of 198 global companies, with 759 subsidiaries, located in 16 different countries. The research, which they explained in their forthcoming book on China and Global Value Chains, found that 32.7 percent of these suppliers were Japanese, 28.5 percent American, 19.0 percent Taiwanese, 6.5 percent European, and only 3.95 percent Chinese. Of the 391 subsidiaries providing highest-value “core components,” 40.4 percent were American, 26.8 percent Japanese, 10.7 percent Taiwanese, 9.2 percent Korean, and only 2.2 percent Chinese.

To put it simply, more than half of the components of Apple’s products are imported into China, and practically none of the important core technologies are made by Chinese companies. Nearly all of the intellectual property in Apple’s products originates from outside China. The researchers found that the few subsidiaries that foreign companies located in China that were producing core components were largely involved in the production and testing of products for just-in-time delivery to locations for final assembly.

China surely isn’t happy with this situation. Having spent billions of dollars in state-led investment, its domestic production of semiconductors accounts for less than 13 percent of the country’s demand, and its ability to design and produce this critical input remains seriously constrained according to East-West Center’s Dieter Ernst. That is why the national focus is on moving further up the value chain and creating intellectual property.

American companies no longer have the financial motivation to sell their souls and deal with the risks. That is why I expect the trickle of manufacturing returning to U.S. shores will, over the next few years, become a flood.

Vivek Wadhwa is Distinguished Fellow at Carnegie Mellon University Engineering at Silicon Valley and author of The Driver in the Driverless Car: How Our Technology Choices Will Create the Future.