为啥在颤振项目中添加启动器图标时出现错误?
Posted
技术标签:
【中文标题】为啥在颤振项目中添加启动器图标时出现错误?【英文标题】:Why am I getting errors while adding launcher icon in flutter project?为什么在颤振项目中添加启动器图标时出现错误? 【发布时间】:2022-01-15 09:36:45 【问题描述】:所以,我正在尝试用我的图标更改默认的颤振启动器图标。我正在使用来自pub.dev 的flutter_launcher_icons: ^0.9.2
。
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
但是当我运行 flutter pub run flutter_launcher_icons:main
时,我收到错误消息:
════════════════════════════════════════════
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
而且图标没有改变。
可能是什么问题?
=> 我的意思是,因为它以前工作过很多次...
【问题讨论】:
删除命令有效吗? 试用版0.9.2
。它不会修复它,但它可能会给出更好的错误?
【参考方案1】:
转到android/app/build.gradle
并将minSdkVersion
和targetSdkVersion
更改为整数值。
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
然后做剩下的,即
pub.get -> flutter pub run flutter_launcher_icons:main
【讨论】:
【参考方案2】:解决问题的另一种方法,这也对我有用。
关于
这个错误主要是由于android: true
引起的,我在参考了很多文章后尝试使用
(pubspec.yaml)
flutter_icons:
image_path: "images/icon.png"
android: false
ios: true
它只对 ios 有效,之后我得到了一个用于 ios 的推荐代码。我加了。
flutter_icons:
image_path: "images/icon.png"
android: false
ios: true
remove_alpha_ios: true //recommendation added
最后一步
(可选)
错误是我做的
检查你是否在同一个文件中写了任何额外的代码,因为我在文件build.gradle
中的额外代码遇到了很多麻烦。这一行用于从@获取flutter.minSdkVersion
的值987654328@文件。
def flutterminSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
(android\app\build.gradle)
minSdkVersion 16
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
然后运行常规代码
flutter pub get
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
• Overwriting default iOS launcher icon with new icon
✓ Successfully generated launcher icons
上面的代码最终解决了这个问题,我希望任何人都可以从中得到帮助并节省他/她的宝贵时间。
附上一些资料,这有助于我做出最终裁决。
https://issueexplorer.com/issue/fluttercommunity/flutter_launcher_icons/301 https://github.com/fluttercommunity/flutter_launcher_icons/issues/88
【讨论】:
以上是关于为啥在颤振项目中添加启动器图标时出现错误?的主要内容,如果未能解决你的问题,请参考以下文章
为啥在启动 Spring Boot 应用程序时出现 Gson builder 错误?