Paramedic here! They both serve different purposes. CPR keeps blood circulating to keep one’s brain and other important organs alive. An AED will detect the activity of someone’s heart and if it is a specific rhythm it will shock it. Cardiac arrest isn’t always a flat line, it can be the heart quivering or ineffectively pumping. This shock stops the heart briefly and then hopefully their heart will return to a normal rhythm.
In the simplest terms I can think of, someone in cardiac arrest needs both. Without CPR their brain will die. Without an AED they are less likely to come out of cardiac arrest and will just remain dead.