This has been happening since Xcode 10.
I have an app that uses PJSIP. When I archive, I get the same error. I have to then remove all references of the library out of the app, delete all the headers from the filesystem. Then I have to archive again and let the process fail. After this I can revert the changes and then it works fine.
When I want to debug app again, I need to follow the same process and then I can debug until I need to archive again.
So this, in my opinion points to some sort of internal Xcode caching issue when linking an external library.
I have tried all the different cleanup methods available on the internet. I have even created a new sample app with only the PJSIP library, I have even reset the mac to factory default, cleared derived data etc.. Nothing works, except the workaround that I found.
At least I have a workaround, its just a pain.