所以,我正在尝试用我的图标更改默认的 flutter 启动器图标。我正在使用
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
并且图标没有改变。
=> 我的意思是,因为它以前工作过很多次......
转到
android/app/build.gradle
并将 minSdkVersion
和 targetSdkVersion
更改为整数值。
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
然后做剩下的事情,即
pub.get -> flutter pub run flutter_launcher_icons:main
解决问题的另一种方法,对我也有效。
这个错误主要是由于
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
中获取android\local.properties
的值文件。
def flutterminSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
(android pp uild.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
我遇到了同样的问题并找到了解决方案
1.添加如下依赖 [pubspec.yaml]
dependencies:
flutter:
sdk: flutter
flutter_launcher_icons: ^0.9.2 // add lib as here
2。添加以下行 [pubspec.yaml]
flutter_icons:
image_path: "assets/launcher_icon.png"
android: true
ios: true
remove_alpha_ios: true
3.打开
local.properties
文件并添加以下行[android\local.properties]
flutter.minSdkVersion=21
4.现在转到
app/build.gradle
文件并添加以下内容(如果不存在): [应用程序级别 > build.gradle]
def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = flutter.minSdkVersion.toString()
}
5.然后转到
defaultConfig
中的
build.gradle
[转到下面的同一文件]
替换此行>
minSdkVersion flutter.minSdkVersion
有了这个 >
minSdkVersion flutterMinSdkVersion
6。转到
build.gradle
并保存
7。转到
local.properties
并保存
8。进入android studio运行下面
flutter pub get
flutter pub run flutter_launcher_icons:main
它会起作用的:)!
我碰巧注意到 https://pub.dev/packages/flutter_launcher_icons_maker - 第一次就成功了。 (在我长时间的尝试和破坏过程中,这里的解决方案对我来说都不起作用,这需要更多的时间来修复:()。
用
flutter pub remove flutter_launcher_icons
移除原件,然后按照说明进行操作即可。
通过替换此行解决(android/app/build.gradle) flutter_launcher_icons 在 minSdjVersion 21 以下不起作用
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
}
对于即将到来的用户,这里有一个简单的修复: 如果您没有
flutter.minSdkVersion
属性,请将其添加到 local.properties 文件中:
flutter.minSdkVersion=21
之后,转到 app/build.gradle 文件并添加以下内容(如果不存在):
def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = flutter.minSdkVersion.toString()
}
然后在默认配置中:像这样编辑它:
defaultConfig {
applicationId 'com.example'
minSdkVersion flutterMinSdkVersion.toString()
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
然后运行 flutter launcher icon 命令:
flutter pub get
flutter pub run flutter_launcher_icons:main
转到 android/app/build.gradle 并将 minSdkVersion 和 targetSdkVersion 更改为整数值。
minSdkVersion 21 目标SDK版本29 versionCode flutterVersionCode.toInteger() 版本名称 flutterVersionName
然后做剩下的事情,即
flutter 酒吧获取 flutter pub 运行 flutter_launcher_icons:main
就我而言,我 改变了
flutter_launcher_icons: ^0.9.2
到
flutter_launcher_icons: ^0.9.1
那就解决了。
有同样的问题,它通过更改 minsdk、targetsdk 和compilesdk 来工作,然后我删除了该包,然后通过此代码行再次添加它:
flutter pub add flutter_launcher_icons
当然,我这样做时没有删除 pubspec.yaml 文件中的此代码行:
flutter_icons:
image_path: assets/food-delivery_app_icon.png
android: true
ios: true
但我也发现奇怪的是,它在成功消息中写入了包的 0.9.1 版本而不是 0.9.2 版本作为添加包的代码行,获取最新版本的包
问题是由 flutter_launcher_icons 设置中的配置引起的:
flutter_launcher_icons:
android: "launcher_icon"
ios: true
image_path: "assets/icon/icon.png"
如果创建 Flutter 项目时没有选择 iOS 支持,只选择 Android,设置 ios: true 会报错。
解决问题: 从配置中删除 ios: true 行。
进行此更改后,错误应该消失。