Well, I mean, the easiest ways is to…co-author with a female author.
This works across the board. When Eunice and I set out to write our contemporary urban fantasy, she wanted to make the protagonist a Brirish-born Chinese woman because she is a British-born Chinese woman, and never had an opportunity to see protagonists like herself when she was growing up. (Though in most other ways, May is nothing like Eunice—certainly not in her romantic or sexual life!)
I would not have attempted to write a British-born Chinese woman as a protagonist on my own—ot’s way too far outside my lived experience. Even the character’s relationship with her Hong Kong expat parents is outside my experience.
Writing with someone who has lived some part of the life you’re trying to convey in your story is a good way to avoid most of the traps.
Can’t do that? Then get beta readers who are women. Hire manuscript readers who belong to whatever group you’re writing about.
And for Heaven’s sake, avoid the trap of the horny postadolescent man writing female characters: