2

I have updated Flutter to 2.5.0 in my project and getting a lot of errors, for example:

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.

or

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]];

or

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);

There are HUNDREDS of them, about different packages and pods. I have upgraded all dependencies, I have tried flutter clean, flutter pub cache repair, deleting Pods and Podfile.lock, it doesn't help. Also, I can't find issues about it in packages repos or flutter repo.

My 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.

And 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.
  • It looks like a lot of packages are not compatible with Flutter 2.5.0, but how can this be? And no issues in their repos about it. I think it suggests that I am doing something wrong. – Alexey Prilepskiy Sep 16 '21 at 07:46
  • 1
    Wait, none of those examples you gave are actually errors because it says "warning" rather than "error". Maybe some of the hundreds of messages are true errors and those are the ones you should share. – Ryan Heise Sep 16 '21 at 07:57
  • Hmm, interesting! So it's because of the last errors in this log? https://gist.github.com/prilepskiy/5f4ea7d82395351f17afd0e06379b75c But how I can resolve it and how to resolve all of these warnings... Anyway, thanks, i didn't think about it @RyanHeise – Alexey Prilepskiy Sep 16 '21 at 10:13
  • I see some issues about this problem in the photo_view repo, so I think it's way, I'll start from this :) But I'm still worried about hundreds of warnings – Alexey Prilepskiy Sep 16 '21 at 10:42
  • 1
    Try building with `--verbose` command there you can find the actual errors. Your snaps are only warnings. I currently face similar errors after `XCode` update, haven't solved them yet though. – esentis Sep 16 '21 at 11:34
  • Thanks, I think I'm not ready to upgrade for 2.5.0 :) – Alexey Prilepskiy Sep 16 '21 at 12:23

3 Answers3

0

I faced this type error and fixed following below steps:

  1. Go to terminal and command: cd ios then ENTER
  2. sudo gem install cocoapods copy and paste in the terminal
  3. pod init
  4. pod install
  5. pod update

After finish above process open simulator and run on there.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • Thank you and I'm sorry, but are you sure? I have installed cocoapods and also have Podfile in this project. Unfortunately, it didn't help either :( – Alexey Prilepskiy Sep 16 '21 at 07:42
0

In build.gradle I changed 30 into 31

android {
    compileSdkVersion 31

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
Nimantha
  • 6,405
  • 6
  • 28
  • 69
btm me
  • 368
  • 3
  • 11
0

For people who are coming here after updating their flutter versions to 2.8 you can do something like this to fix this,

Add these lines to the local.properties file in the android folder

flutter.minSdkVersion = 23
flutter.targetSdkVersion = 30
flutter.compileSdkVersion = 30
Achintha Isuru
  • 2,662
  • 18
  • 24