こんにちは、CX事業本部 Delivery部の若槻です。
今回はFlutterでのiOSアプリ開発時のTipsとなります。
Info.plistをVSCodeから編集したい
Info.plist
は、iOSアプリ開発でのビルド時にユーザー定義定数などの情報を渡すためのファイルです。Flutterプロジェクトではios/Runner/Info.plist
のパスに配置されます。
Info.plist
<?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>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Flutter Sample App</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>flutter_sample_app</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
さてこのInfo.plist
を編集する際に私は今までXcodeを立ち上げてメニューから設定を行うようにしていました。
なぜなら、VS Codeでは既定の動作でXML形式のファイルは保存時に次のように自動フォーマットされてしまうからです。
Info.plist(自動フォーマット後)
<?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>
CFBundleDevelopmentRegion
</key>
<string>
$(DEVELOPMENT_LANGUAGE)
</string>
<key>
CFBundleDisplayName
</key>
<string>
Flutter Sample App
</string>
<key>
CFBundleExecutable
</key>
<string>
$(EXECUTABLE_NAME)
</string>
<key>
CFBundleIdentifier
</key>
<string>
$(PRODUCT_BUNDLE_IDENTIFIER)
</string>
<key>
CFBundleInfoDictionaryVersion
</key>
<string>
6.0
</string>
<key>
CFBundleName
</key>
<string>
flutter_sample_app
</string>
...略
</dict>
</plist>
しかしこのフォーマット済みの形式だと、アプリのビルド時にThis is sometimes caused by a malformed plist file
となりビルドが失敗してしまいます。
しかしInfo.plist
を編集するためだけにXcodeを立ち上げるのは手間です。特にFlutterの場合ですと開発をするためにXcodeを立ち上げておく必要が無いのでなおさらです。
自動フォーマットを無効にしてVSCodeから編集可能とする
VS Codeのsettings.json
で、editor.formatOnSave
をfalse
に変更(チェックを外す)して無効にます。
するとInfo.plist
を編集して保存しても自動でフォーマットがされなくなります。
その他フォーマッター機能との兼ね合い
Prettierなどのフォーマッター機能でファイル保存時の自動でフォーマットを利用するためには、VSCodeのeditor.formatOnSave
を有効にしておく必要があります。
よって、Info.plist
を編集し終えたらeditor.formatOnSave
を有効に戻しておくと良いかと思います。
参考
以上