18
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Last updated at Posted at 2019-06-03

はじめに

  • 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ツールなどを使って自動化したいですね
  • 気が向いたら挑戦してみたいと思います
18
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?