You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter升级至3.0.5后iOS构建失败,寻求解决方案

Flutter 3.0.5升级后iOS构建失败解决指南

环境信息

  • MacOS Monterey 12.5
  • Xcode 13.4.1
  • Flutter 3.0.5(稳定通道)
  • Dart 2.17.6
  • DevTools 2.12.2

问题概述

升级Flutter至3.0.5后,iOS构建失败,日志存在大量重复输出,关键错误及警告已提取。已尝试删除iOS目录重建、清理缓存更新Pods等操作,均未解决问题。

已尝试的修复操作

  • 删除iOS文件夹后执行 flutter create .
  • 依次执行:flutter clean → pod deintegrate → pod repo update → pod install → pod update

关键错误日志

Writing result bundle at path:
    /var/folders/f9/7grwc3ls1wb7q21j989mvww00000gn/T/flutter_tools.LCeiN7/flutter_ios_build_temp_dirhFJ00P/temporary_xcresult_bundle

/Users/username/Desktop/packageName/ios/Pods/libwebp/src/enc/backward_references_enc.c:694:12: warning: variable 'best_offset' may be uninitialized when used here [-Wconditional-uninitialized]
          (best_offset << MAX_LENGTH_BITS) | (uint32_t)best_length;
           ^~~~~~~~~~~
/Users/username/Desktop/packageName/ios/Pods/libwebp/src/enc/backward_references_enc.c:626:20: note: initialize the variable 'best_offset' to silence this warning
    int best_offset;
                   ^
                    = 0
1 warning generated.
4 warnings generated.

/Users/userName/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-9.5.0/ios/Classes/FlutterLocalNotificationsPlugin.m:13:3: warning: 'UILocalNotification' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationRequest [-Wdeprecated-declarations]
  UILocalNotification *_launchNotification;
  ^
In module 'UIKit' imported from /Users/userName/Desktop/packageName/ios/Pods/Target Support Files/flutter_local_notifications/flutter_local_notifications-prefix.pch:2:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/System/Library/Frameworks/UIKit.framework/Headers/UILocalNotification.h:18:12: note: 'UILocalNotification' has been explicitly marked deprecated here
@interface UILocalNotification : NSObject<NSCopying, NSCoding>

/Users/username/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/ios/Classes/ReachabilityConnectivityProvider.swift:23:5: warning: result of call to 'ensureReachability()' is unused
    ensureReachability()
    ^                 ~~
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_auth-3.3.20/lib/src/recaptcha_verifier.dart:57:27: Error: Required named parameter 'auth' must be provided.
      _factory.delegateFor(
                          ^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/in_app_purchase-0.5.2/lib/src/in_app_purchase/google_play_connection.dart:32:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance!.addObserver(this);

../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/extended_image_library-3.2.0/lib/src/platform.dart:41:28: Warning: Operand of null-aware operation '?.' has type 'PaintingBinding' which excludes null.
 - 'PaintingBinding' is from 'package:flutter/src/painting/binding.dart' ('../../Developer/flutter/packages/flutter/lib/src/painting/binding.dart').
    return PaintingBinding.instance?.imageCache;
                           ^
../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/confetti-0.6.0/lib/src/confetti.dart:229:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance!.addPostFrameCallback((_) {


Failed to package /Users/username/Desktop/packageName.
Command PhaseScriptExecution failed with a nonzero exit code
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in dependency order

Result bundle written to path:
    /var/folders/f9/7grwc3ls1wb7q21j989mvww00000gn/T/flutter_tools.LCeiN7/flutter_ios_build_temp_dirhFJ00P/temporary_xcresult_bundle

当前Podfile内容

# Uncomment this line to define a global platform for your project
platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
 installer.pods_project.targets.each do |target|
 flutter_additional_ios_build_settings(target)
  target.build_configurations.each do |config|
   config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
  end
 end
end

解决方案

1. 修复firebase_auth必填参数错误

日志中明确显示firebase_auth-3.3.20版本与Flutter 3.0.5不兼容,缺少必填的auth参数。直接升级firebase_auth到兼容版本:
在pubspec.yaml中更新依赖:

firebase_auth: ^4.10.0 # 替换为当前最新兼容版本,可通过pub.dev查询

执行 flutter pub get 更新依赖。

2. 升级第三方适配Flutter 3.0+空安全

日志中的空安全警告、API弃用提示,都是因为依赖库版本未适配Flutter 3.0+的更新,需升级以下库:

  • flutter_local_notifications:升级到^16.0.0+,解决UILocalAPI弃用问题
  • connectivity_plus:升级到^4.0.0+,解决未使用返回值警告
  • in_app_purchase:升级到^3.1.0+,修复空安全调用问题
  • extended_image_library:升级到^4.0.0+,修复PaintingBinding调用问题
  • confetti:升级到^0.7.0+,修复WidgetsBinding调用问题

3. 消除libwebp警告(可选)

libwebp的未初始化变量警告不影响构建,若需消除,修改Podfile的post_install块:

post_install do |installer|
 installer.pods_project.targets.each do |target|
 flutter_additional_ios_build_settings(target)
  target.build_configurations.each do |config|
   config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
   # 添加以下代码忽略libwebp警告
   if target.name == 'libwebp'
     config.build_settings['WARNING_CFLAGS'] = '-Wno-conditional-uninitialized'
   end
  end
 end
end

4. 重新执行构建流程

完成依赖更新后,执行以下命令清理并重建:

flutter clean
cd ios
pod deintegrate
rm Podfile.lock
pod repo update
pod install
cd ..
flutter build ios

内容的提问来源于stack exchange,提问作者Seongchan Kim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:45:33