升级到flutter 2.5.0后出现很多错误
Posted
技术标签:
【中文标题】升级到flutter 2.5.0后出现很多错误【英文标题】:A lot of errors after upgrade to flutter 2.5.0 【发布时间】:2021-11-11 04:07:10 【问题描述】:我在我的项目中已经将 Flutter 更新到 2.5.0 并且出现了很多错误,例如:
Failed to build ios app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
/flutter/.pub-cache/hosted/pub.dartlang.org/audio_service-0.18.0/ios/Classes/AudioServicePlugin.m:213:59: warning: 'initWithImage:' is deprecated: first deprecated in iOS 10.0 - Use -initWithBoundsSize:requestHandler: [-Wdeprecated-declarations]
artwork = [[MPMediaItemArtwork alloc] initWithImage: artImage];
^
In module 'MediaPlayer' imported from /flutter/.pub-cache/hosted/pub.dartlang.org/audio_service-0.18.0/ios/Classes/AudioServicePlugin.m:3:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItem.h:244:1: note: 'initWithImage:' has been explicitly marked deprecated here
- (instancetype)initWithImage:(UIImage *)image MP_DEPRECATED("Use -initWithBoundsSize:requestHandler:", ios(5.0, 10.0));
^
1 warning generated.
/flutter/.pub-cache/hosted/pub.dartlang.org/audio_service-0.18.0/ios/Classes/AudioServicePlugin.m:213:59: warning: 'initWithImage:' is deprecated: first deprecated in iOS 10.0 - Use -initWithBoundsSize:requestHandler: [-Wdeprecated-declarations]
artwork = [[MPMediaItemArtwork alloc] initWithImage: artImage];
^
In module 'MediaPlayer' imported from /flutter/.pub-cache/hosted/pub.dartlang.org/audio_service-0.18.0/ios/Classes/AudioServicePlugin.m:3:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/MediaPlayer.framework/Headers/MPMediaItem.h:244:1: note: 'initWithImage:' has been explicitly marked deprecated here
- (instancetype)initWithImage:(UIImage *)image MP_DEPRECATED("Use -initWithBoundsSize:requestHandler:", ios(5.0, 10.0));
^
1 warning generated.
或
ios/Pods/Reachability/Reachability.m:465:63: warning: cast to smaller integer type 'unsigned int' from 'Reachability *' [-Wpointer-to-int-cast]
NSStringFromClass([self class]), (unsigned int) self, [self currentReachabilityFlags]];
^~~~~~~~~~~~~~~~~~~
1 warning generated.
ios/Pods/Reachability/Reachability.m:465:63: warning: cast to smaller integer type 'unsigned int' from 'Reachability *' [-Wpointer-to-int-cast]
NSStringFromClass([self class]), (unsigned int) self, [self currentReachabilityFlags]];
或
1 warning generated.
/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.7.0/ios/Classes/FlutterDownloaderPlugin.m:373:15: warning: 'stringByReplacingPercentEscapesUsingEncoding:' is deprecated: first deprecated in iOS 9.0 - Use -stringByRemovingPercentEncoding instead, which always uses the recommended UTF-8 encoding. [-Wdeprecated-declarations]
? [origin stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
^
In module 'Foundation' imported from /flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.7.0/ios/Classes/DBManager.h:8:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSURL.h:598:1: note: 'stringByReplacingPercentEscapesUsingEncoding:' has been explicitly marked deprecated here
- (nullable NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)enc API_DEPRECATED("Use -stringByRemovingPercentEncoding instead, which always uses the recommended UTF-8 encoding.", macos(10.0,10.11), ios(2.0,9.0), watchos(2.0,2.0), tvos(9.0,9.0));
^
/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.7.0/ios/Classes/FlutterDownloaderPlugin.m:973:21: warning: 'UILocalNotification' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationRequest [-Wdeprecated-declarations]
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
^
In module 'UIKit' imported from /Meduza/meduza-dart/ios/Pods/Target Support Files/flutter_downloader/flutter_downloader-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalNotification.h:18:12: note: 'UILocalNotification' has been explicitly marked deprecated here
@interface UILocalNotification : NSObject<NSCopying, NSCoding>
^
/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.7.0/ios/Classes/FlutterDownloaderPlugin.m:973:84: warning: 'UILocalNotification' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationRequest [-Wdeprecated-declarations]
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
^
In module 'UIKit' imported from /Meduza/meduza-dart/ios/Pods/Target Support Files/flutter_downloader/flutter_downloader-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalNotification.h:18:12: note: 'UILocalNotification' has been explicitly marked deprecated here
@interface UILocalNotification : NSObject<NSCopying, NSCoding>
^
/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_downloader-1.7.0/ios/Classes/FlutterDownloaderPlugin.m:975:56: warning: 'presentLocalNotificationNow:' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's -[UNUserNotificationCenter addNotificationRequest:withCompletionHandler:] [-Wdeprecated-declarations]
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
^
In module 'UIKit' imported from /Meduza/meduza-dart/ios/Pods/Target Support Files/flutter_downloader/flutter_downloader-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:236:1: note: 'presentLocalNotificationNow:' has been explicitly marked deprecated here
- (void)presentLocalNotificationNow:(UILocalNotification *)notification API_DEPRECATED("Use UserNotifications Framework's -[UNUserNotificationCenter addNotificationRequest:withCompletionHandler:]", ios(4.0, 10.0)) API_UNAVAILABLE(tvos);
其中有 数百个,关于不同的包和 pod。我已经升级了所有的依赖项,我试过flutter clean
,flutter pub cache repair
,删除Pods和Podfile.lock,它没有帮助。另外,我在包 repos 或 flutter repo 中找不到关于它的问题。
我的flutter doctor
:
[✓] Flutter (Channel stable, 2.5.0, on macOS 11.5.2 20G95 darwin-x64, locale en-LV)
[✗] android toolchain - develop for Android devices
✗ Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
[✓] Xcode - develop for iOS and macOS
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google
Chrome)
! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio (not installed)
[✓] VS Code (version 1.59.1)
[✓] Connected device (1 available)
! Doctor found issues in 3 categories.
还有flutter pub outdated
:
Showing outdated packages.
[*] indicates versions that are not the latest available.
Package Name Current Upgradable Resolvable Latest
direct dependencies:
characters *1.1.0 *1.1.0 *1.1.0 1.2.0
photo_view *0.11.1 *0.11.1 *0.11.1 0.12.0
worker_manager *4.2.3 *4.2.3 *4.2.3 4.2.4
dev_dependencies: all up-to-date.
transitive dependencies:
async *2.8.1 *2.8.1 *2.8.1 2.8.2
flutter_widget_from_html_core *0.6.2 *0.6.2 *0.6.2 0.7.0
matcher *0.12.10 *0.12.10 *0.12.10 0.12.11
test_api *0.4.2 *0.4.2 *0.4.2 0.4.3
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.
【问题讨论】:
貌似很多包都不兼容Flutter 2.5.0,怎么会这样呢?他们的回购中没有关于它的问题。我认为这表明我做错了什么。 等等,你给出的这些例子实际上都不是错误,因为它说的是“警告”而不是“错误”。也许数百条消息中有一些是真正的错误,而这些正是您应该分享的。 嗯,有趣!所以这是因为这个日志中的最后一个错误? gist.github.com/prilepskiy/5f4ea7d82395351f17afd0e06379b75c 但是我该如何解决它以及如何解决所有这些警告......无论如何,谢谢,我没有考虑过@RyanHeise 我在 photo_view repo 中看到了一些关于这个问题的问题,所以我认为是这样,我将从这个开始:) 但我仍然担心数百个警告 尝试使用--verbose
命令构建您可以找到实际错误。您的快照只是警告。我目前在XCode
更新后遇到了类似的错误,但还没有解决。
【参考方案1】:
对于在将 Flutter 版本更新到 2.8 后来到这里的人,您可以执行以下操作来解决此问题,
将这些行添加到 android 文件夹中的 local.properties 文件中
flutter.minSdkVersion = 23
flutter.targetSdkVersion = 30
flutter.compileSdkVersion = 30
【讨论】:
【参考方案2】:在 build.gradle 我把 30 改成了 31
android
compileSdkVersion 31
sourceSets
main.java.srcDirs += 'src/main/kotlin'
【讨论】:
他要求的是 iOS 错误而不是 android【参考方案3】:我遇到了这种类型的错误,并按照以下步骤进行了修复:
-
转到终端并命令:cd ios 然后 ENTER
sudo gem install cocoapods
终端复制粘贴
pod init
pod install
pod update
完成上述过程后打开模拟器并在那里运行。
【讨论】:
谢谢你,我很抱歉,但你确定吗?我已经安装了 cocoapods,并且在这个项目中也有 Podfile。不幸的是,它也没有帮助:(以上是关于升级到flutter 2.5.0后出现很多错误的主要内容,如果未能解决你的问题,请参考以下文章
Flutter 升级后出现 Flutter Cloud Firestore 错误