Gems are used to speed up building construction and recruiting times, move cities, upgrade alliances, declare war on capitals, and a variety of other purposes. You can also purchase resources, items, and buffs in the Item Store.  Gems are earned in a variety of ways including completing in-game quests, as a reward for attacking NPC camps, completing various ad-based tasks, or paying USD.