Tesla announced Tuesday the embattled electric car company plans to build a factory in Shanghai, dramatically increasing its notoriously constrained production capacity.

CEO Elon Musk said the plant, whose plans have reportedly been in the works for a year, would eventually have an annual production capacity of 500,000 cars, adding that he hoped it would be “completed very soon.”

A joint announcement released by Shanghai’s government said a preliminary agreement had been signed to build the plant in the commercial hub’s Lingang district.“Shanghai will be the location for the first Gigafactory outside the United States,” said Musk. “It will be a state-of-the-art vehicle factory and a role model for sustainability. We hope it will be completed very soon.”

The announcement has raised questions about how the new facility will be paid for. Tesla benefits from millions in U.S. government subsidies and has been burning through billions of dollars as it has struggled to raise the rate of production of its more “affordable” Model 3 car. At the end of the first quarter, the company had just $2.7 billion of cash on its balance sheet.

According to reports, Tesla’s new factory would be the first in China’s to be wholly owned by a non-Chinese carmaker. The U.S. has criticized China for requiring foreign manufacturers to partner with domestic Chinese companies, a practice the U.S. says facilitates theft of U.S. intellectual property and technology.

But that may not be enough to prevent China from stealing Tesla technology.

“On Tuesday, Tesla also signed an electric vehicle investment agreement with Shanghai’s Lingang Management Committee, the Lingang Area Development Administration and the Lingang Group. A development and innovation center will also be set up. In theory, this is where a technology transfer could happen, even without a joint venture company,” Bloomberg columnist Anjani Trevedi pointed out. “That would defeat the purpose of having a wholly owned enterprise.”

It would take approximately two years before production begins and then up to three more years before it reaches full production. “Tesla is deeply committed to the Chinese market, and we look forward to building even more cars for our customers here,” a spokesperson for the car company said. “Today’s announcement will not impact our US manufacturing operations, which continue to grow.”

Tesla last month told shareholders that it was working with officials in Shanghai on establishing the plant, which would build electric cars and battery packs.

At the time, Musk claimed the electric carmaker was being reorganized to speed up production of Model 3 vehicles — a key to profitability at the fast-growing firm.

Expectations of an impending announcement spiked following reports Musk would travel to Shanghai on Tuesday, followed by a visit to Beijing. The joint announcement said “Tesla plans to construct and operate a wholly-owned” factory in Shanghai. China typically requires that foreign automakers set up joint ventures with Chinese firms when establishing auto manufacturing plants.

Tesla has been looking to expand into global markets, plans that faced a potential threat from intensifying trade frictions and President Donald Trump’s push to keep manufacturing jobs at home.

In keeping with his campaign promise to crack down on Beijing’s unfair trade practices, the United States Friday on pulled the trigger on 25 percent duties on roughly $34 billion in Chinese machinery, electronics and high-tech equipment, including autos, computer hard drives and LEDs. President Trump has for years slammed what he describes as Beijing’s underhanded economic treatment of the United States, with the trade deficit in goods with China ballooning to a record $375.2 billion last year. The move triggered immediate and similar retaliatory tariffs by China — perhaps heightening Tesla’s urgency in reaching a deal with Shanghai.

Tesla’s announcement to build a Chinese manufacturing plant comes mere days after Musk inserted himself into the rescue effort for 12 boys and their soccer coach trapped inside a south Thailand cave. Musk flew to Chiang Rai and offered various solutions to extract those inside the cave — but none were used. The billionaire even constructed a miniature “submarine” equipped with oxygen tanks and the ability to shuttle one person.

Just returned from Cave 3. Mini-sub is ready if needed. It is made of rocket parts & named Wild Boar after kids’ soccer team. Leaving here in case it may be useful in the future. Thailand is so beautiful. pic.twitter.com/EHNh8ydaTT — Elon Musk (@elonmusk) July 9, 2018

Some observers were critical of Musk’s actions, branding them as a cynical attempt to garner positive media coverage. “Elon Musk is well known to have an eye for the headlines, but to be fair he only became involved after a message from one of his army of fans on Twitter,” said BBC technology reporter Rory Cellan-Jones. “The fact that his company’s space technology and its much vaunted tunnelling skills proved irrelevant to the operation is a reminder that sometimes this tech superhero doesn’t quite match up to the Iron Man of his fans’ dreams.”

Tesla’s China plant further contradicts Musk’s explicit criticism of China’s predatory trade practices in March. He replied to a tweet from President Trump which expressed dismay over the unfair playing field U.S. products face when exported to China. “China has been asked to develop a plan for the year of a One Billion Dollar reduction in their massive Trade Deficit with the United States,” President Trump tweeted. “Our relationship with China has been a very good one, and we look forward to seeing what ideas they come back with. We must act soon!”

China has been asked to develop a plan for the year of a One Billion Dollar reduction in their massive Trade Deficit with the United States. Our relationship with China has been a very good one, and we look forward to seeing what ideas they come back with. We must act soon! — Donald J. Trump (@realDonaldTrump) March 7, 2018

“Do you think the US & China should have equal & fair rules for cars? Meaning, same import duties, ownership constraints & other factors,” Musk replied.

Do you think the US & China should have equal & fair rules for cars? Meaning, same import duties, ownership constraints & other factors. — Elon Musk (@elonmusk) March 8, 2018

The billionaire went on to note that a vehicle manufactured in the U.S. and exported to China is levied with a 25 percent import tax. Conversely, China only pays a 2.5 percent import tax when shipping their vehicles to America — “a tenfold difference,” Musk pointed out.

For example, an American car going to China pays 25% import duty, but a Chinese car coming to the US only pays 2.5%, a tenfold difference — Elon Musk (@elonmusk) March 8, 2018

Musk also noted “no US auto company is allowed to own even 50% of their own factory in China, but there are five 100% China-owned EV auto companies in the US.”

Also, no US auto company is allowed to own even 50% of their own factory in China, but there are five 100% China-owned EV auto companies in the US — Elon Musk (@elonmusk) March 8, 2018

China announced in May it will slash tariffs on imported cars, a move that could benefit the global auto industry. China’s Finance Ministry said auto tariffs will be reduced from 25% to “around 13.8%,” and levies on car parts will come down from 10% to 6%. The reduced levies took effect on July 1st.

The Agence France-Presse contributed to this report.