I can build and run my app on my device, but when I tried to build archive, I got many errors. The errors are about my 3rd library - google protobuf. It showed that #error H
When you build to run, Xcode usually builds for the active architecture only. When you archive it builds all the architectures specified by the intersection of the Build Settings "Architectures and Valid Architectures".
So it's likely that Xcode is trying to build for some architecture that isn't supported by your protobuf library, e.g. Arm64.