In a way that is irritating, unpleasant, or harsh; in a manner that causes friction or annoyance.
From 'grating' (harsh or irritating), which derives from 'grate' (to rub harshly or irritate), plus the adverbial suffix '-ly'. The sense of irritation has been present since the 1600s.
The word splits into two meanings depending on context: a grating sound (like a cheese grater), but also anything that 'grates on' someone—and both come from the same image of uncomfortable friction.
Complete word intelligence in one call. Free tier — 50 lookups/day.