简体   繁体   中英

Why am I getting errors while adding launcher icon in flutter project?

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...

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, ie

pub.get -> flutter pub run flutter_launcher_icons:main

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

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:) !

Solved with replacing this line (android/app/build.gradle)

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example"
    minSdkVersion 21
    targetSdkVersion flutter.targetSdkVersion
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
}

I happen to notice https://pub.dev/packages/flutter_launcher_icons_maker - which worked 1st go. (None of the solutions here worked for me during many hours of trying - and breaking stuff - that took even more time to fix:( ).

Remove the original with flutter pub remove flutter_launcher_icons then follow the instructions and be happy.

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

In my case I changed

flutter_launcher_icons: ^0.9.2

to

flutter_launcher_icons: ^0.9.1

and that's be fix.

Had the same issue and it worked by changing the minsdk, targetsdk, and compilesdk then I deleted the package then added it again through this code line:

flutter pub add flutter_launcher_icons

of course, I did so while not deleting this code line in pubspec.yaml file:

flutter_icons:
 image_path: assets/food-delivery_app_icon.png
 android: true
 ios: true

But the weird thing I found as well is that it wrote in the success message the 0.9.1 version of the package not the 0.9.2 ver as the code line to add the package, gets the latest version of the package

Evidence of What I Said

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, ie

flutter pub get flutter pub run flutter_launcher_icons:main

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM