President Trump has said he started a trade war to create jobs in America. But foreign carmakers that employ thousands of workers in the United States are gauging whether tariffs, the main weapon in that war, may compel them to shift jobs to, of all places, China.

Carmakers’ early hopes that congressional Republicans who favor free trade could restrain Mr. Trump have faded. Instead, manufacturers are girding for a protracted period of conflict that will disrupt supply chains and change the companies’ calculations about where to expand and where to cut back.

BMW, the largest exporter of cars from the United States, has already moved some production of its popular X3 sport utility vehicle — once made exclusively in Spartanburg, S.C. — to a factory in Shenyang, China. Analysts expect the German automaker to also move some production of its larger X5.

By shifting production, BMW can avoid China’s punitive tariffs on cars imported from the United States, which have ensnared foreign automakers with large American factories. It could also insulate BMW if Mr. Trump follows through on his threat to tax imported vehicles and parts, a move that would further increase the cost of building cars in the United States and selling them abroad.