In a packaged-food industry suffering from weak demand and shifting consumer tastes, there’s still one safe bet: salty snacks.

Potato chips, popcorn and other savory fare have remained strong sellers, even as other categories languish. And that’s driving companies’ M&A strategies: Campbell Soup Co. (NYSE: CPB) and Hershey Co. (NYSE: HSY) both announced deals on that give them well-known savory brands.

Campbell is acquiring Snyder’s-Lance Inc. for about $4.9 billion in cash, adding Cape Cod potato chips, Snyder’s pretzels and Pop Secret popcorn to its portfolio. Hershey, meanwhile, is snapping up Amplify Snack Brands Inc., spending roughly $921 million for a business that’s best known for SkinnyPop popcorn.

It’s no coincidence that the two deals are targeting the same category, said Ken Shea, an analyst at Bloomberg Intelligence. “It’s a group that’s been growing consistently,” he said.

Campbell and Hershey occupy different parts of the supermarket, but their core products are suffering a similar form of stagnation. Canned soup has lost favor with many Americans, sending Campbell into a three-year slump. At Hershey, management is grappling with sugary treats becoming more taboo -- especially its hallmark milk chocolate.

As tastes change, the 10 largest packaged-food companies in the U.S. have seen about $17 billion in revenue evaporate over the past three years. Consumers are seeking out more fresh food, which is typically found on the perimeter of supermarkets. Breakfast cereal and other longtime staples are increasingly getting left out of grocery carts.

Though potato chips and pretzels aren’t typically viewed as healthy, they’ve remained popular with Americans seeking convenience and on-the-go snacking. And the category of pre-popped popcorn, such as SkinnyPop, has surged in recent years.

Campbell’s expects the Snyder’s-Lance deal to begin adding to earnings by fiscal 2019, which ends in July of that year. The Camden, New Jersey-based company has already seen the power of savory snacks within its current lineup. While soup has slumped, sales of its Goldfish crackers have helped boost results.

Salty snacks have posted growth in each of the past four years, according to Bloomberg Intelligence.

“This acquisition will dramatically transform Campbell, shifting our center of gravity,” Chief Executive Officer Denise Morrison said in a statement.

Campbell has stumbled in previous attempts to update its stable of brands, particularly with a push into fresh food. The company’s 2012 purchase of Bolthouse Farms has been marred by a product recall and struggles in that unit’s carrot farming business.

In July, Campbell announced a $700 million deal to buy Pacific Foods of Oregon, which makes organic soup and broth. It also invested $10 million in the meal-kit startup Chef’d earlier this year. Through that partnership, Campbell has started touting recipes that feature its products.

Hershey is paying a 71 percent premium for Austin, Texas-based Amplify, which also makes Tyrrell’s potato chips, Paqui chips and Oatmega protein bars.

Even with the salty-snack tailwind, the takeover target has struggled in its two-plus years as a publicly traded business. Amplify, which has about $600 million in debt, had lost more than half its value since its initial public offering in 2015.

Hershey’s move indicates that new CEO Michele Buck is serious about broadening the company’s image, Susquehanna International Group analyst Pablo Zuanic said in a note.

It also reflects the chocolate-bar giant’s commitment to being an acquirer, rather than an acquisition. The maker of Kisses candy rejected a takeover bid from Mondelez International Inc. last year.

Hershey signaled its shift away from chocolate in early 2015, when it acquired Krave Pure Foods, a maker of premium beef jerky with about $35 million in sales. Krave, based in California’s wine country, put Hershey in the fast-growing meat-snack category and gave the company access to Whole Foods customers. Hershey has said Krave could be a $500 million brand.

The goal is to generate $2 billion in snack revenue, with a quarter of that coming from meat products. Monday’s deal should help push Hershey closer to that overall target.

“It shows management’s commitment to its broader snack strategy,” Zuanic said.