Why am I getting errors while adding launcher icon in flutter project?
Solution 1
Go to android/app/build.gradle
and change the minSdkVersion
and targetSdkVersion
to integer values.
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Then do the rest, i.e.
pub.get -> flutter pub run flutter_launcher_icons:main
Solution 2
Another way to fix the issue, which also worked for me.
About
This error is mainly caused due to the android: true
, when I tried after following many articles by using
(pubspec.yaml)
flutter_icons:
image_path: "images/icon.png"
android: false
ios: true
it worked only for ios, after which I got a recommendation code to be used for ios. I added.
flutter_icons:
image_path: "images/icon.png"
android: false
ios: true
remove_alpha_ios: true //recommendation added
Final Step
(Optional)
mistakes are done by me
Just check if you have written any extra code in the same file because I faced a lot of trouble due to my extra code in the file build.gradle
.This line is used to fetch the value of flutter.minSdkVersion
from the android\local.properties
file.
def flutterminSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
(android\app\build.gradle)
minSdkVersion 16
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
And then running the usual code
flutter pub get
flutter pub run flutter_launcher_icons:main
and I got the output
════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v0.9.1)
════════════════════════════════════════════
• Creating default icons Android
• Overwriting the default Android launcher icon with a new icon
• Overwriting default iOS launcher icon with new icon
✓ Successfully generated launcher icons
ultimately the above code solves the issue, I hope anyone can get help from this and save his/her valuable time.
Attaching some sources, which helped me in the final verdict.
https://issueexplorer.com/issue/fluttercommunity/flutter_launcher_icons/301 https://github.com/fluttercommunity/flutter_launcher_icons/issues/88
Solution 3
For Upcoming Users, here a simple fix:
If you don't have a flutter.minSdkVersion
property, then add it to local.properties file:
flutter.minSdkVersion=21
After That go to app/build.gradle file and add this if not present:
def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = flutter.minSdkVersion.toString()
}
Then in default config: edit it like this:
defaultConfig {
applicationId 'com.example'
minSdkVersion flutterMinSdkVersion.toString()
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Then run the flutter launcher icon command:
flutter pub get
flutter pub run flutter_launcher_icons:main
Solution 4
I faced the same problem and found a solution
1.Add dependancy as below [pubspec.yaml]
dependencies:
flutter:
sdk: flutter
flutter_launcher_icons: ^0.9.2 // add lib as here
2. add below line [pubspec.yaml]
flutter_icons:
image_path: "assets/launcher_icon.png"
android: true
ios: true
remove_alpha_ios: true
3.Open local.properties
file and add below line [android\local.properties]
flutter.minSdkVersion=21
4.Now go to app/build.gradle
file and add this if not present: [app level > build.gradle]
def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = flutter.minSdkVersion.toString()
}
5.Then go to defaultConfig
in build.gradle
[go to below same file]
replace this line > minSdkVersion flutter.minSdkVersion
with this > minSdkVersion flutterMinSdkVersion
6. go to build.gradle
and save
7. go to local.properties
and save
8. go to android studio and run below
flutter pub get
flutter pub run flutter_launcher_icons:main
It will work :) !
MNBWorld
I am new to the coding world. I am here to eat all your heads by asking questions to finish up my projects.😁✌
Updated on November 23, 2022Comments
-
MNBWorld over 1 year
So, I am trying change the default flutter launcher icon with my one. I am using the
flutter_launcher_icons: ^0.9.2
from pub.dev. The code in pubspec.yaml:dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 hexcolor: ^2.0.5 google_fonts: ^2.1.0 flutter_neumorphic: ^3.2.0 flutter_launcher_icons: ^0.9.2 dev_dependencies: flutter_lints: ^1.0.4 flutter_test: sdk: flutter flutter_icons: image_path: "assets/icon/icon.png" android: true ios: true
But when I am running
flutter pub run flutter_launcher_icons:main
, I am getting error saying:════════════════════════════════════════════ FLUTTER LAUNCHER ICONS (v0.9.1) ════════════════════════════════════════════ ✓ 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:309:18) #3 createIconsFromConfig (package:flutter_launcher_icons/main.dart:94:47) #4 createIconsFromArguments (package:flutter_launcher_icons/main.dart:60:7) #5 main (file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.9.2/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
And the Icon doesn't change.
What probably the problem?
=> I mean, coz it worked many times before...