Animals eat Plants or other animals. But the primary source of energy is Sun. The plants which is eaten by animals get energy from Sun by Photosynthesis.
Energy is transferred from plants to animals. When these animals are eaten by other animals, this energy is further transferred.
Sun → Plants (Producers) → Herbivores → Carnivores
Ultimately, the energy is from Sun. So all animals and plants are dependent on Sun for energy