(CNN)It was the awkward moment beamed around the world.
Chinese President Xi Jinping and Japanese Prime Minister Shinzo Abe, meeting for the first time as leaders in 2014, shook hands, their gaze downcast, expressions grim.
Both men seemed determined to avoid any hint that they were enjoying the encounter at a forum in Beijing.
Four years later, Abe is about to receive a far warmer reaction when he arrives in Beijing Thursday for his first official visit to China in years.
And it is largely thanks to US President Donald Trump.
The Trump administration’s unconventional foreign policy toward trade and military alliances has left Tokyo feeling unsure of the US support which has underlined its international relations since the end of World War II.
The president has repeatedly urged military allies in east Asia to pay for their own defense, teasing the end of a US military presence in the region while encouraging Japan to buy more American weapons.
Across the East China Sea, Beijing finds itself increasingly under pressure from the Trump administration and in desperate need of diplomatic and economic allies in the region.
“Both Japan and China are being targeted by the US,” Koichi Nakano, professor of political science, at Tokyo’s Sophia University told CNN. “Xi Jinping wants to say to Abe that they are in this together.”
Beijing and Tokyo have historically had very different relationships with Washington — one borderline adversarial, the other a close alliance — but both countries now face similar complaints from the Trump administration.
Trump’s disputes with China are well known, given the unfolding consequences for the global economy and diplomatic arena.
Billions of dollars in Chinese goods have been slapped with tariffs by the Trump administration, while US authorities accuse China of widespread theft of intellectual property.
In recent months, the dispute has spread beyond economic concerns into military and political issues, with unsupported claims by Trump that Beijing was interfering in US elections.
But for Japan, the conflict is more complicated and unexpected. The US has been a close military and diplomatic ally of Tokyo for more than 70 years.
Abe was the first international leader to meet Trump after the 2016 US presidential election.
Despite multiple meetings, and a concerted effort to court the US President, the Japanese government has been left mostly empty-handed.
“All the fantasy, and the Shinzo-Donald thing, have not really led to any special treatment for Japan, but rather often quite rude and hostile attitudes when it comes to trade issues,” Koichi told CNN.
Diplomatically, Abe was left out in the cold during high-profile negotiations with North Korea during this year’s talks between Pyongyang, Washington and Seoul, a snub which was felt deeply in Tokyo.
Unlike other US allies such as Australia, Japan wasn’t exempted from Trump’s tariffs on imports of steel and aluminum, while the US President has also spoken harshly about trade with Japan.
In April, Trump tweeted that Japan had “hit us hard on trade for years.” The country has a trade surplus of nearly $70 billion with the US.
“Trump’s political consciousness on trade is straight out of the 1980s, with Japan … If you’re looking for consistency, he believes that Japan and South Korea don’t play fair on trade and he’s stuck to that view,” Richard McGregor, senior fellow at Sydney’s Lowy Institute, told CNN.
Still, despite the US hostility pushing Beijing and Tokyo closer together, the two countries’ long and fractious history makes an easy and lasting rapprochement difficult.
Relations have been rocky ever since the end of World War II amid recriminations over Japan’s brutal occupation of parts of China.
Progress towards “normalizing” relationsfoundered in 2012 when a long simmering feud over a barren set of islands claimed by both China and Japan boiled over in public protests and threats of retaliation.
The dispute over who owned the Diaoyu Islands, known as the Senkakus in Japan, led to a rapid chilling of diplomatic relations culminating in that chilly meeting between Abe and Xi in 2014.
At the same time, culture wars over Japan’s occupation of China have resurfaced, with Beijing politicizing wartime atrocities while nationalists in Tokyo argue their country should recapture its national pride.
The unlikely warming of relations between the two countries began in September 2017 when Abe became the first Japanese leader in 15 years to attend the Chinese embassy’s National Day celebrations.
Since then, Abe and Xi have met multiple times at international summits, with each country praising the others’ efforts to improve relations. In May, Chinese Premier Li Keqiang became the highest profile Chinese leader to meet Japan’s Emperor Akihito in almost a decade.
Experts say with Trump pushing both countries on trade and security issues, China and Japan are desperate to smooth over regional relations as they seek allies to help them weather the US storm.
“China is looking for a friend so that means they’re much more willing to accommodate Japan and overlook their severe, strategic differences. The same goes for Japan, in some sense,” McGregor said.
While China needs Japan’s help to push back against Trump’s trade actions, Japan is desperate to protect the current liberal economic order in the region, Stephen Nagy, visiting fellow at the Japan Institute for International Affairs, told CNN.
“Their concern is if relations continue to worsen there’s going to be an American market and a (separate, closed) Chinese market … which will add to the cost of business of Japanese companies,” he said. “They don’t want to this to happen.”
For now, both countries seem enthusiastic to promote free trade, at least publicly. In an interview with the South China Morning Post in the runup to Abe’s arrival in Beijing, the Chinese ambassador to Japan, Cheng Yonghua, touted the countries’ “highly complimentary” economies.
“We should not sit idly by and be indifferent to the damage to global trade and the global supply chain,” he said. “We should be united in voicing our resolute support for free trade and opposition to protectionism.”
But the growing rapprochement between the two countries doesn’t mean all issues between Tokyo and Beijing have been resolved, nor is it guaranteed to last.
Last week the Chinese Foreign Ministry sternly and publicly rebuked Abe for sending ritual offerings to the Yasukuni Shrine, the temple in Tokyo which honors a number of convicted war criminals.
“We urge Japan to squarely face up to and reflect upon its invasion history,” Foreign Ministry spokesman Lu Kang said.
While US presidents and their policies come and go, deep-running disagreements between China and Japan over history and territory remain hugely divisive and have yet to be resolved.
“These underlying, more fundamental, issues are likely to be more relevant and more influential than the temporary factor that is Trump,” Koichi said.