I tried to codesign using:
/usr/bin/codesign -f -s $IDENTITY --keychain $KEYCHAIN --entitlements $ENTITLEMENTS Payload/Test.app
But I get a
I was having the same error, ended up being an "Invalid" provisioning profile but only showed invalid on the Apple Developer portal. And Invalid not Expired.
Just went in hit edit, then save, and new profile worked fine.