[英]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.所以,我正在尝试用我的一个更改默认的 flutter 启动器图标。 I am using the
flutter_launcher_icons: ^0.9.2
from pub.dev .我正在使用来自pub.dev的
flutter_launcher_icons: ^0.9.2
。 The code in pubspec.yaml: 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 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
And the Icon doesn't change.并且图标不会改变。
=> I mean, coz it worked many times before... => 我的意思是,因为它以前工作过很多次......
Go to android/app/build.gradle
and change the minSdkVersion
and targetSdkVersion
to integer values. Go 到
android/app/build.gradle
并将minSdkVersion
和targetSdkVersion
更改为 integer 值。
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Then do the rest, ie然后做rest,即
pub.get -> flutter pub run flutter_launcher_icons:main
Another way to fix the issue, which also worked for me.解决问题的另一种方法,这也对我有用。
This error is mainly caused due to the android: true
, when I tried after following many articles by using此错误主要是由于
android: true
引起的,当我尝试使用以下许多文章后
(pubspec.yaml) (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.它仅适用于 ios,之后我得到了用于 ios 的推荐代码。 I added.
我补充说。
flutter_icons:
image_path: "images/icon.png"
android: false
ios: true
remove_alpha_ios: true //recommendation added
(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.只需检查您是否在同一个文件中编写了任何额外的代码,因为我在文件
build.gradle
中的额外代码遇到了很多麻烦。此行用于从android\local.properties
文件中获取flutter.minSdkVersion
的值.
def flutterminSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
(android\app\build.gradle) (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我得到了 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 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] 1.添加如下依赖[pubspec.yaml]
dependencies:
flutter:
sdk: flutter
flutter_launcher_icons: ^0.9.2 // add lib as here
2. add below line [pubspec.yaml] 2. 添加以下行[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] 3.打开
local.properties
文件并添加以下行[android\local.properties]
flutter.minSdkVersion=21
4.Now go to app/build.gradle
file and add this if not present: [app level > build.gradle] 4.现在 go 到
app/build.gradle
文件,如果不存在则添加: [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] 5.然后 go 到
build.gradle
中的defaultConfig
[转到下面的同一文件]
replace this line > minSdkVersion flutter.minSdkVersion
替换此行 >
minSdkVersion flutter.minSdkVersion
with this > minSdkVersion flutterMinSdkVersion
有了这个 >
minSdkVersion flutterMinSdkVersion
6. go to build.gradle
and save 6. go 到
build.gradle
并保存
7. go to local.properties
and save 7. go 到
local.properties
并保存
8. go to android studio and run below 8. go 转 android studio 并在下面运行
flutter pub get
flutter pub run flutter_launcher_icons:main
It will work:) !它会工作:)!
Solved with replacing this line (android/app/build.gradle)解决了替换这一行(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.我碰巧注意到https://pub.dev/packages/flutter_launcher_icons_maker - 它在第一个 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.删除带有
flutter pub remove flutter_launcher_icons
然后按照说明进行操作并感到高兴。
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
属性,则将其添加到 local.properties 文件:
flutter.minSdkVersion=21
After That go to app/build.gradle file and add this if not present:之后 go 到 app/build.gradle 文件,如果不存在则添加:
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 启动器图标命令:
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:有同样的问题,它通过更改 minsdk、targetsdk 和 compilesdk 起作用,然后我删除了 package 然后通过以下代码行再次添加它:
flutter pub add flutter_launcher_icons
of course, I did so while not deleting this code line in pubspec.yaml file:当然,我这样做并没有在 pubspec.yaml 文件中删除此代码行:
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但我也发现奇怪的是它在成功消息中写了 package 的 0.9.1 版本而不是 0.9.2 版本作为添加 package 的代码行,得到最新版本的 package,得到最新版本的 ZEFE907A8D03A6E7607A8D03A6E
Go to android/app/build.gradle and change the minSdkVersion and targetSdkVersion to integer values. Go 到 android/app/build.gradle 并将 minSdkVersion 和 targetSdkVersion 更改为 integer 值。
minSdkVersion 21 targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName minSdkVersion 21 targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName
Then do the rest, ie然后做rest,即
flutter pub get flutter pub run flutter_launcher_icons:main flutter 发布 flutter 发布运行 flutter_launcher_icons:main
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.