When Western companies moved manufacturing to China, it was all about minimizing costs. China was a developing country with labor costs amongst 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. By 2014, China’s manufacturing-cost advantage over the U.S. had shrunk to less than 5%, according to Boston Consulting Group. 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 difficult to hire large numbers 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.

Robot advancements

Robots have advanced so far that they can do the work of Chinese workers. Foxconn’s FXCOF, 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 packing the boxes the goods are shipped in.

Assembling automobiles is one of the most difficult of all manufacturing tasks. But with the help of a new generation of robots, Tesla TSLA, +5.04% was able to ramp up production at its Fremont, Calif., factory to produce about 80,000 cars per quarter. It did this cost effectively in a region that has among the highest labor costs in the world.

Moving out of China

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 high-value, high-technology manufacturing such, as what Apple AAPL, +3.75% does in China for all of its products except the MacBook Pro, which is 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 hadn’t feared that China would steal their intellectual property as it has been doing in its efforts to become an innovation powerhouse by 2020 — a focus of China’s 13th Five Year National Plan on Scientific and Technological and Innovation.

In 2015, the supply chain for Apple’s products consisted of 198 global companies, with 759 subsidiaries, located in 16 different countries, according to Seamus Grimes of National University of Ireland and Yutao Sun of Dalian University of China. The research, detailed in their forthcoming book “China and Global Value Chains,” found that 33% of these suppliers were Japanese, 29% American, 19% Taiwanese, 6.5% European and only 4% Chinese. Of the 391 subsidiaries providing highest-value “core components,” 40% were American, 27% Japanese, 11% Taiwanese, 9.2% Korean and only 2.2% 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 unhappy

China surely isn’t happy with this situation. Having dedicated billions of dollars in state-led investment, its domestic production of semiconductors accounts for less than 13% of the country’s demand, and its ability to design and produce this critical input remains seriously constrained, according to Dieter Ernst of Honolulu’s East-West Center. 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 that the trickle of manufacturing returning to U.S. shores will, over the next few years, become a flood.

Vivek Wadhwa is a Distinguished Fellow at Harvard Law School and Carnegie Mellon’s School of Engineering at Silicon Valley. He is the author, with Alex Salkever, of “Your Happiness Was Hacked: Why Tech Is Winning the Battle to Control Your Brain — and How to Fight Back.” Follow him on Twitter @wadhwa.