この記事を読んだら分かること
Flutterでflutter_launcher_iconsを使ってアイコンを設定するときのエラーの対処ができ、アプリアイコンを設定できる!!
エラー内容
FormatException: Invalid number (at character 1)
解決方法
pubspec.yml
を下記のようにすればOK
dart 2.8の問題らしくgithubでIssueが立ってます。
pubspec.yml
flutter_lints: ^1.0.0
flutter_launcher_icons:
git:
url: https://github.com/Davenchy/flutter_launcher_icons.git
ref: fixMinSdkParseFlutter2.8
flutter_icons:
android: true
ios: true
# 画像ファイルのパスを指定する
image_path: "lib/assets/icon.png"
修正確認
ターミナルで、下記のコマンドを実行する
$ flutter pub run flutter_launcher_icons:main
結果(成功)
════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v0.9.1)
════════════════════════════════════════════
• Creating default icons Android
• Overwriting the default Android launcher icon with a new icon
WARNING: Icons with alpha channel are not allowed in the Apple App Store.
Set "remove_alpha_ios: true" to remove it.
• Overwriting default iOS launcher icon with new icon
✓ Successfully generated launcher icons
結果(失敗例)
════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v0.8.0)
════════════════════════════════════════════
✓ Successfully generated launcher icons
Unhandled exception:
FormatException: Invalid number (at character 1)
^
#0 int._handleFormatError (dart:core-patch/integers_patch.dart:129:7)
#1 int.parse (dart:core-patch/integers_patch.dart:55:14)
#2 minSdk (package:flutter_launcher_icons/android.dart:294:18)
#3 createIconsFromConfig (package:flutter_launcher_icons/main.dart:90:47)
#4 createIconsFromArguments (package:flutter_launcher_icons/main.dart:58:7)
#5 main (file:///Users/cnctrk/develop/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.8.1/bin/main.dart:6:26)
#6 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#7 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
pub finished with exit code 255
Succesfullyって出るけど失敗してるのが分かりづらかった・・・
ちなみにアイコン画像は1枚だけ用意すればOKです。(正方形比率、劣化しないPNGがいいと思う)
サイズのバリエーションはパッケージ側で勝手にやってくれます。