I'm playing a fighter who has taken the crossbow expert feat which allows me to not have disadvantage within five feat of an opponent. Do I still need to be using a melee attack to gain advantage from flanking?
It depends - the text of the rules are inconsistent.
Rules-as-written, whether or not the flanking optional rules benefits your crossbow fighter depends on one crucial question... hexes or squares?
Flanking on Squares. When a creature and at least one of its allies are adjacent to an enemy and on opposite sides or corners of the enemy's space, they flank that enemy, and each of them has advantage on melee attack rolls against that enemy.
Flanking on Hexes. When a creature and at least one of its allies are adjacent to an enemy and on opposite sides of the enemy's space, they flank that enemy, and each of them has advantage on attack rolls against that enemy.
Even if you're using hexes, I would suggest that the rules as intended were that you must be using a melee attack to gain the benefit of flanking, and this is an oversight in the hex-based flanking description. I would have looked back to previous editions' rules about flanking to help gauge the intention; however, 3.5e and 4e actually disagree on this subject. Where 3.5e mandates a melee attack, 4e offers the benefit to any attack against a flanked enemy. So, that's no help...
However, were I your GM, I'd personally not need much persuading to allow a Crossbow Expert feat-user to gain the benefit of flanking if making a ranged attack against an adjacent enemy - and given the inconsistency within the rule itself, plus the fact it is an optional rule to begin with, it's really the GM's call as to whether flanking is melee-only or not.
Yes, Flanking only requires an Attack Roll.
The Variant flanking rules from the DMG on page 251 state (emphasis mine):
...gives combatants a simple way to gain advantage on attack rolls against a common enemy.
Thus, the attack can be any Attack Roll (ranged, melee, or spell.)
A difference of language
As Carcer notes in their answer, the language for Flanking on Squares is different than that of Hexes AND that of the intro on flanking. Whether or not the error is in the Squares text or in the other two places is unknown without an errata, but given that it is the same in two places and different in one, I think we can assume the difference is the outlier and that flanking only requires an Attack Roll.