title: XCode expects development certificate when trying to distribute app built on Flutter. ERROR ITMS-90161
body: <p>XCode expects a development certificate with my provisioning profile when I am actually trying to do a distribution.</p>
  <p><strong>More details</strong></p>
  <p>I am trying to push an update to an iOS app on app store, that was initially built by another developer using Flutter. Using <code>flutter build ipa</code> and uploading the archive through XCode simply never worked, it always got stuck in the uploading screen. So I tried Transporter after getting an ipa with <code>flutter build ios --release</code> <a href="https://stackoverflow.com/a/69807619/6419531">[1]</a>. Using automatic signing so far, Out of almost 50 tries, only one went through for some reason. The rest of the time I see the following error.</p>
  <pre><code>ERROR ITMS-90161: &quot;Invalid Provisioning Profile. The provisioning profile included in the bundle com.spoonmoney.app [Payload/Runner.app] is invalid. [Missing code-signing certificate]. A Distribution Provisioning profile should be used when submitting apps to the App Store. For more information, visit the iOS Developer Portal.&quot; 
  </code></pre>
  <p><strong>Transporter error while uploading</strong>
  <a href="https://i.stack.imgur.com/MqP1W.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MqP1W.jpg" alt="Transporter" /></a>
  <strong>Details of automatic signing</strong>
  <a href="https://i.stack.imgur.com/GQhFJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GQhFJ.png" alt="Automating signing includes development certificate" /></a></p>
  <p>When I try to do manual signing with a valid provisioning profile which includes distribution cert, Xcode shows this error:</p>
  <p><a href="https://i.stack.imgur.com/uJuMw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uJuMw.png" alt="Manual signing error" /></a>
  Details of profile
  <a href="https://i.stack.imgur.com/vVC26.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vVC26.png" alt="enter image description here" /></a></p>
  <p><strong>Things to note</strong></p>
  <ul>
  <li>I tried clearing relevant certificates and profiles both from my Keychain access and developer profile and created new ones. No improvement.</li>
  <li>Tried clearing signing certificates in Flutter <code>flutter config --clear-ios-signing-cert</code></li>
  <li>I have an active developer program membership.</li>
  </ul>