NEW YORK — While Dwayne Johnson and Kevin Hart loved teaming up in the buddy action film “Central Intelligence” (opening June 17), they had a bigger reason for signing on to the project.

“We both wanted to be part of a movie that sends a strong anti-bullying message,” Hart said, sitting next to Johnson in a Manhattan hotel suite.

Johnson, the actor formerly known as the wrestler The Rock, said, “It’s something we both saw in high school — and even in college — and I know that’s true for virtually everyone in America.”

In the movie, Johnson plays Bob, once a horribly bullied teenage geek who grew up to be a muscular marvel and hot CIA agent.

Hart’s Calvin character was the opposite: a former high school big-man-on-campus (despite his short stature) who has become a respectable but bland middle-management accounting executive. Calvin believes his best years are in his past — back in his glory days in high school.

When they reconnect, prior to their 20th reunion, the film takes off in a faster-paced direction, with Calvin unwittingly being sucked into Bob’s battle with the agency — which now considers him a rogue agent who must be destroyed.

“High school is so formative,” said Johnson. “In many ways, so much of what we later become was forged during those key four years.”

Said Hart: “I love the fact that this movie shows how challenging it can be for people on both sides of the spectrum. There are the Calvins who were once hot but now not so much, and the Bobs who were horribly bullied and have moved on but still carry a lot of that trauma with them even today.

“The interesting thing here is that Bob doesn’t get that Calvin feels he’s no longer the big deal and still sees him as Calvin ‘The Jet’ from high school who came to his defense at the moment of Bob’s greatest humiliation in the school gym — in front of the entire school.

While making “Central Intelligence,” Johnson kept thinking of real-life Bob characters ridiculed in high school in the real world.

“Yet beyond being the butts of jokes, there were so many who were totally invisible to the bulk of the other kids in high school,” he said. “In a sense, being invisible — kind of like being a non-person — is perhaps even worse.”

Hart told a story from his own high school years in Philadelphia.

“There was this girl who I saw every day in the cafeteria, and every day these other kids would throw a fruit cup at her head. Finally, one day I just couldn’t take it any more. The thing was, the girl didn’t even react — she was so used to it being a daily occurrence. Anyway, I walked over to her and helped her get the fruit out of her hair and helped clean herself up.

“After that, she simply smiled at me — the first time I think I had ever seen her smile — and said, ‘Thank you.’

“The best part: No one ever threw a fruit cup at her ever again.”

Director Rawson Marshall Thurber, who previously helmed “We’re the Millers,” said: “So many of the issues and traumas we deal with in high school stay with us forever. . . . There’s a reason people say, ‘Life IS high school.’

“I think that’s very true. While who you are in high school doesn’t necessarily form who you are afterward, it can inform who you are afterward. That goes for both good and bad things.

“A lot of people have a really tough time in high school. The most important thing about the movie: Yes, it’s got action, it’s got comedy, it’s got two of the biggest stars in the world in it, but it shows a lot of heart at the end.”

Thurber told a story involving one of the film’s many extras.

“One of the women came up to me explaining we were shooting in her own high school, where her class was holding its reunion in two weeks in the very gym where we were filming.

“She had been bullied in high school and had not intended to attend her reunion. But after being part of a key scene in the film, where she watched Kevin give that emotional anti-bullying speech, she told me she was now going to go to her reunion with her head held high.

“That really made my day,” Thurber said.