Campbell Soup and Hershey Co. buy makers of savory treats, still strong sellers, to add to their pre-packaged food portfolios.

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’ merger and acquisition strategies: Campbell Soup Co. and Hershey Co. both announced deals Monday 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, 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.

Campbell shares rose as much as 2.2 percent to $50.66 on Monday in the wake of the announcement. Snyder’s-Lance climbed 6.9 percent to $50.01, in line with the deal price.

Hershey rose up to 1 percent to $115.32. Amplify, whose ticker BETR is meant to convey the idea of better snacking, gained as much as 72 percent to $12.01, close to its $12-a-share transaction price.

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 written statement Monday.

Snacks will account for about half of Campbell’s net sales after the deal is completed, with soup making up about 25 percent, Morrison said on a conference call.

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.