[英]Why am I getting errors while adding launcher icon in flutter project?
所以,我正在嘗試用我的一個更改默認的 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
並且圖標不會改變。
=> 我的意思是,因為它以前工作過很多次......
Go 到android/app/build.gradle
並將minSdkVersion
和targetSdkVersion
更改為 integer 值。
minSdkVersion 21
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
然后做rest,即
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
中的額外代碼遇到了很多麻煩。此行用於從android\local.properties
文件中獲取flutter.minSdkVersion
的值.
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
我得到了 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
最終上面的代碼解決了這個問題,我希望任何人都可以從中得到幫助並節省他/她的寶貴時間。
附上一些資料,這有助於我做出最終判決。
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.現在 go 到app/build.gradle
文件,如果不存在則添加: [app level > build.gradle]
def flutterMinSdkVersion = localProperties.getProperty('flutter.minSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = flutter.minSdkVersion.toString()
}
5.然后 go 到build.gradle
中的defaultConfig
[轉到下面的同一文件]
替換此行 > minSdkVersion flutter.minSdkVersion
有了這個 > minSdkVersion flutterMinSdkVersion
6. go 到build.gradle
並保存
7. go 到local.properties
並保存
8. go 轉 android studio 並在下面運行
flutter pub get
flutter pub run flutter_launcher_icons:main
它會工作:)!
解決了替換這一行(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
}
我碰巧注意到https://pub.dev/packages/flutter_launcher_icons_maker - 它在第一個 go 工作。 (在我嘗試和破壞東西的數小時內,這里的解決方案都沒有對我有用,這需要更多的時間來修復:()。
刪除帶有flutter pub remove flutter_launcher_icons
然后按照說明進行操作並感到高興。
對於即將到來的用戶,這里有一個簡單的修復:如果您沒有flutter.minSdkVersion
屬性,則將其添加到 local.properties 文件:
flutter.minSdkVersion=21
之后 go 到 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 啟動器圖標命令:
flutter pub get
flutter pub run flutter_launcher_icons:main
就我而言,我改變了
flutter_launcher_icons: ^0.9.2
至
flutter_launcher_icons: ^0.9.1
這就是修復。
有同樣的問題,它通過更改 minsdk、targetsdk 和 compilesdk 起作用,然后我刪除了 package 然后通過以下代碼行再次添加它:
flutter pub add flutter_launcher_icons
當然,我這樣做並沒有在 pubspec.yaml 文件中刪除此代碼行:
flutter_icons:
image_path: assets/food-delivery_app_icon.png
android: true
ios: true
但我也發現奇怪的是它在成功消息中寫了 package 的 0.9.1 版本而不是 0.9.2 版本作為添加 package 的代碼行,得到最新版本的 package,得到最新版本的 ZEFE907A8D03A6E7607A8D03A6E
Go 到 android/app/build.gradle 並將 minSdkVersion 和 targetSdkVersion 更改為 integer 值。
minSdkVersion 21 targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName
然后做rest,即
flutter 發布 flutter 發布運行 flutter_launcher_icons:main
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.