Help us understand the problem. What is going on with this article?

FlutterでiOSアプリをビルドしてDeploy Gateで配信する

はじめに

  • Androidアプリは簡単にビルドとDeploy Gate配信ができたけどiOSアプリは手間がかかったので忘れないように書いておく
  • iOS CertificatesはIn-House and Ad Hocで取得済みの前提で書いていきます
  • FlutterもiOSアプリ開発も良くわかっておりません

ビルド

  • 何も設定しないとビルドエラーになるのでエラーメッセージに従って対応していきます
$ flutter build ios --release
Building com.example.flutterTflite for device (ios-release)...
════════════════════════════════════════════════════════════════════════════════
No valid code signing certificates were found
You can connect to your Apple Developer account by signing in with your Apple ID
in Xcode and create an iOS Development Certificate as well as a Provisioning 
Profile for your project by:
  1- Open the Flutter project's Xcode target with
       open ios/Runner.xcworkspace
  2- Select the 'Runner' project in the navigator then the 'Runner' target
     in the project settings
  3- In the 'General' tab, make sure a 'Development Team' is selected. 
     You may need to:
         - Log in with your Apple ID in Xcode first
         - Ensure you have a valid unique Bundle ID
         - Register your device with your Apple Developer Account
         - Let Xcode automatically provision a profile for your app
  4- Build or run your project again
  5- Trust your newly created Development Certificate on your iOS device
     via Settings > General > Device Management > [your new certificate] > Trust

For more information, please visit:
  https://developer.apple.com/library/content/documentation/IDEs/Conceptual/
  AppDistributionGuide/MaintainingCertificates/MaintainingCertificates.html

具体的な対応

  • $ open ios/Runner.xcworkspace を実行してビルドの設定を開く
  • Identity -> Bundle Identifier Bundle Idを入力する
  • Runner -> General -> Signing -> Team 適切なTeamを選択する
  • Runner -> General -> Deployment Info 必要に応じてDeployment Targetを設定する
    • 利用したいFlutterプラグインが9.0+のサポートだったので9.0に設定

再ビルド

$ flutter build ios --release
  • エラーが出なければOK、appが出来るがこの形式ではDeploy Gateで配信ができません

ipaファイル作成とUDID登録

  • Deploy Gateにはipa形式のファイルが必要
  • しかしFlutterにはipaを作成するコマンドなどはないっぽい?
  • なのでこれから書いていく手順でipaファイルを作りました
  • またiOSデバイスのUDIDの登録が必要

UDID登録

exportOptions.plistファイル作成

  • ios/exportOptions.plist を作成する
  • your_bundle_id, your_provisioning_profile_name, your_team_id を書き換えます
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>provisioningProfiles</key>
    <dict>
      <key>**your_bundle_id**</key>
      <string>**your_provisioning_profile_name**</string>
    </dict>
    <key>method</key>
    <string>ad-hoc</string>
    <key>teamID</key>
    <string>**your_team_id**</string>
    <key>uploadBitcode</key>
    <false/>
    <key>uploadSymbols</key>
    <true/>
  </dict>
</plist>

ipaファイル作成

cd ios
xcodebuild -workspace Runner.xcworkspace -scheme Runner -sdk iphoneos -configuration Release archive -archivePath $PWD/build/Runner.xcarchive
xcodebuild -allowProvisioningUpdates -exportArchive -archivePath $PWD/build/Runner.xcarchive -exportOptionsPlist exportOptions.plist -exportPath $PWD/build/Runner.ipa
  • $PWD/build/Runner.ipa にファイルできます
  • これをDeploy Gateにアップロードすれば実機にインストールできると思います

おわりに

  • どうせならFastlaneやCIツールなどを使って自動化したいですね
  • 気が向いたら挑戦してみたいと思います
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした