(CNN) Less than a week after a historic North Korean missile test, the leaders of the United States and China pledged to work together to stop Kim Jong Un's nuclear missile program.

"Something has to be done," US President Donald Trump said during the brief public portion of a meeting with Chinese President Xi Jinping at the G20 summit in Germany.

There will "eventually be a success" against Pyongyang, Trump said. "It may take longer than I'd like. It may take longer than you'd like. But there will be success in the end one way or the other."

Xi told Trump that China remains "firmly committed to denuclearizing the (Korean) peninsula," according to a report from China's state-run Xinhua news agency.

A solution on North Korea must come through dialogue and consultation involving the international community, Xi said.

Missile tested that could reach Alaska

Tensions between the US and North Korea spiked last week, when Pyongyang tested its first intercontinental ballistic missile (ICBM).

Analysts said the test showed the missile could reach much of the US state of Alaska.

The US and South Korea responded with military shows of force, including missile tests of their own and a practice bombing mission from US Air Force B-1 bombers, accompanied by South Korean warplanes.

The response ran counter to China's repeated calls for North Korea's to stop its missile and nuclear tests in exchange for the US and South Korea halting the joint military drills that antagonize the Kim regime.

As a longtime ally of North Korea and its top trading partner, China is seen by many -- including the Trump administration -- as the key to a solution on the Korean Peninsula.

While Trump has in the past praised what appeared to be China's early efforts to exert pressure on its neighbor, he tweeted last month that those efforts had "not worked out."

JUST WATCHED N. Korea blames U.S. for ICBM test, vows more 'gifts' Replay More Videos ... MUST WATCH N. Korea blames U.S. for ICBM test, vows more 'gifts' 02:18

In remarks before their Hamburg meeting, Xi said "sensitive issues still exist" in the US-China relationship that "require a great amount of work."

The leaders appear to have made at least some progress on those issues, according to messages conveyed after the meeting.

Trump tweeted they'd had an "excellent" exchange on trade and North Korea.

Leaving Hamburg for Washington, D.C. and the WH. Just left China's President Xi where we had an excellent meeting on trade & North Korea. — Donald J. Trump (@realDonaldTrump) July 8, 2017

Briefing reporters aboard Air Force One on Saturday, Treasury Secretary Steven Mnuchin said the discussion was "very direct."

"I think there were substantive discussions about the financing of North Korea, we had substantive discussions about ways of dealing with North Korea together," Mnuchin said.

In a lengthy report on the meeting, Chinese state media said Xi had reiterated China's strong opposition to the US deployment of its Terminal High Altitude Area Defense (THAAD) missile defense system in South Korea, which remains a sore point in US-China relations.

While the US says the system is needed for defense against North Korea, China believes it threatens its own security because its radars could be used to spy on Beijing's defense and nuclear deterrent systems.

Closer military ties

The two countries also signaled closer military ties.

Xi proposed that China's defense minister and the US secretary of defense "carry out an exchange of visits as soon as possible," Xinhua reported.

It also said China would participate in the 2018 Rim of the Pacific military exercises, a biennial event known as the world's largest international maritime military exercise.

In 2016, 26 nations, including China, took part in the exercise off Hawaii.

On non-military issues, Xi said a 100-day action plan put into place after his April summit at Trump's Mar-a-logo estate in Florida is bearing fruit and a further year-long plan is being considered, Xinhua reported.

"China and the United States have decided to hold the first round of a comprehensive economic dialogue on July 19, and launch the first round of a law enforcement, cybersecurity, social and cultural dialogue at an early date," Xinhua reported.

A White House statement issued after Saturday's meeting provided none of the specifics listed by Xinhua.

"The two leaders also reviewed work in other areas in the bilateral relationship, including economic issues such as reciprocal trade and market access. President Trump and President Xi directed their security and economic teams to make progress in upcoming dialogues," the White House statement said.

White House officials later said there would be a US-China meeting in Washington this month on a "comprehensive economic dialogue," one of several "substantive issues" Mnuchin said were covered.

Trump's 'comradery' with counterparts

Mnuchin pointed out that the Xi-Trump meeting "lasted over an hour and a half, and would have lasted longer if we didn't have to get pulled out to leave, since we had a time issue."

Meanwhile, Gary Cohn, director of Trump's National Economic Council, gushed about how well Trump gets along with his counterparts, including Xi.

"The relationships that he's building and the comradery that he has is just extraordinary," Cohn said.

"You can see the personal relationship he has with Xi and (Japanese Prime Minister Shinzo) Abe and all these people. The warmness and the openness that's going on between the two of them, it's really extraordinary."