flutter_launcher_icons
は、Flutterプロジェクトでアプリアイコンを簡単に設定できるパッケージです。iOSとAndroidの両方のプラットフォームに対応しており、アプリアイコンの各サイズや解像度を手動で生成する必要がなく、スクリプトが自動的にアイコンを生成します。アイコンを作る手間を大きく削減できます。
flutter pub run flutter_launcher_icons:main
以下のようなエラーが表示されました。
flutter_icons:
ios: true
image_path: "assets/images/launcher/icon_ios.png"
remove_alpha_ios: true
android: true
adaptive_icon_background: "assets/images/launcher/icon_adaptive_background.png"
adaptive_icon_foreground: "assets/images/launcher/icon_adaptive_foreground.png"
エラー内容
Unhandled exception:
PathNotFoundException: Cannot open file, path = 'assets/images/launcher/icon_adaptive_foreground.png' (OS Error: No such file or directory, errno = 2)
指定のファイルが存在しないことが原因です。
libから指定する必要があるようです。
以下の変更をしたら正しくアイコンを設定してくれました。
flutter_icons:
ios: true
image_path: "lib/assets/images/launcher/icon_ios.png"
remove_alpha_ios: true
android: true
adaptive_icon_background: "lib/assets/images/launcher/icon_adaptive_background.png"
adaptive_icon_foreground: "lib/assets/images/launcher/icon_adaptive_foreground.png"
その他のエラー
FormatException: Invalid number (at character 1) →android/app/build.gradle の minSdkVersion などに数値以外が書かれている可能性があります。 PathNotFoundException → アイコン画像ファイルのパスがずれているケースが多いです。まとめ
- flutter_icons で指定するファイルパスは、実際に存在するディレクトリ構造に合わせて正確に記述する。
- 特に assets/ や lib/assets/ のようにディレクトリ階層が深い場合は要注意。
- setup後は flutter pub get → flutter pub run の順でコマンドを実行すれば、スムーズにアイコンを生成できるはずです。