Yes! To earn Affinity XP for a pairing, you need to own both Primals in your collection and have them both active in your combat party.
You don't necessarily need both in your active combat party at all times, completing Energy-based actions will grant Affinity XP for your active pairing regardless of which Primals you're currently using in battle.