Instead of installing cocoapods on your Mac, which needs to be done differently on an M1 chipped machine, it is much easier to add third party frameworks, like Firebase, by using Xcode’s built in Swift Package Manager.
It’s simpler and faster. Here is a link to a video from Chris Ching that explains how to do that.
That might be a solution in a specific case but generally cleaning the Build Folder and/or deleting the DerivedData for that project helps in most cases.