首页 > 解决方案 > Flutter:命令 PhaseScriptExecution 失败且没有错误

问题描述

我在生产中有一个颤振应用程序,我们正在尝试从颤振 1.x 迁移到 2.x。在此过程中,我们遇到了在 ios 中构建的奇怪错误。我们能够通过更新依赖项来修复其中的很大一部分,但我们仍然遇到这个奇怪的问题。最糟糕的是,它似乎只是警告,所以我们有点迷茫。完整的日志可以在这里找到:

    Failed to build iOS app
    Error output from Xcode build:
    ↳
        ** BUILD FAILED **
    
    
    Xcode's output:
    ↳
        ../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_local_notifications-6.0.0/ios/Classes/FlutterLocalNotificationsPlugin.m:13:5: warning: 'UILocalNotification' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationRequest [-Wdeprecated-declarations]
            UILocalNotification *_launchNotification;
            ^
        In module 'UIKit' imported from ../app/app/ios/Pods/Target Support Files/flutter_local_notifications/flutter_local_notifications-prefix.pch:2:
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.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_local_notifications-6.0.0/ios/Classes/FlutterLocalNotificationsPlugin.m:293:4: warning: 'UILocalNotification' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationRequest [-Wdeprecated-declarations]
        - (UILocalNotification *)buildStandardUILocalNotification:(NSDictionary *)arguments {
           ^
        In module 'UIKit' imported from ../app/app/ios/Pods/Target Support Files/flutter_local_notifications/flutter_local_notifications-prefix.pch:2:
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.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_local_notifications-6.0.0/ios/Classes/FlutterLocalNotificationsPlugin.m:752:30: warning: 'UILocalNotification' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's UNNotificationRequest [-Wdeprecated-declarations]
        didReceiveLocalNotification:(UILocalNotification*)notification {
                                     ^
        In module 'UIKit' imported from ../app/app/ios/Pods/Target Support Files/flutter_local_notifications/flutter_local_notifications-prefix.pch:2:
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.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_local_notifications-6.0.0/ios/Classes/FlutterLocalNotificationsPlugin.m:182:64: warning: 'scheduledLocalNotifications' is deprecated: first deprecated in iOS 10.0 - Use UserNotifications Framework's -[UNUserNotificationCenter getPendingNotificationRequestsWithCompletionHandler:] [-Wdeprecated-declarations]
            NSArray *notifications = [UIApplication sharedApplication].scheduledLocalNotifications;
                                                                       ^
        In module 'UIKit' imported from ../app/app/ios/Pods/Target Support Files/flutter_local_notifications/flutter_local_notifications-prefix.pch:2:
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h:242:68: note: 'scheduledLocalNotifications' has been explicitly marked deprecated here
        @property(nullable,nonatomic,copy) NSArray<UILocalNotification *> *scheduledLocalNotifications API_DEPRECATED("Use UserNotifications Framework's -[UNUserNotificationCenter getPendingNotificationRequestsWithCompletionHandler:]", ios
 ....
        ../app/app/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/FIRStorageDownloadTask.m:171:23: warning: 'waitForCompletionWithTimeout:' is deprecated: Use XCTestExpectation instead [-Wdeprecated-declarations]
            [weakSelf.fetcher waitForCompletionWithTimeout:0.001];
                              ^
        In module 'GTMSessionFetcher' imported from ../app/app/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/FIRStorageTask_Private.h:29:
        ../app/app/ios/Pods/GTMSessionFetcher/Source/GTMSessionFetcher.h:1164:5: note: 'waitForCompletionWithTimeout:' has been explicitly marked deprecated here
            __deprecated_msg("Use XCTestExpectation instead");
            ^
        In module 'Foundation' imported from ../app/app/ios/Pods/FirebaseStorage/FirebaseStorage/Sources/Public/FirebaseStorage/FIRStorageDownloadTask.h:17:
        In module 'CoreFoundation' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:6:
        In module 'Darwin' imported from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers/CoreFoundation.h:16:
        /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk/usr/include/sys/cdefs.h:200:48: note: expanded from macro '__deprecated_msg'
                #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                              ^
        1 warning generated.
        ../app/app/ios/Pods/FirebaseDynamicLinks/FirebaseDynamicLinks/Sources/FIRDLJavaScriptExecutor.m:158:12: warning: unused function 'processIsTranslated' [-Wunused-function]
        static int processIsTranslated() {
                   ^
        1 warning generated.
    
        Command PhaseScriptExecution failed with a nonzero exit code
        note: Using new build system
        note: Building targets in parallel
        note: Planning build
        note: Analyzing workspace
        note: Constructing build description
        note: Build preparation complete

Podfile 如下:

# Uncomment this line to define a global platform for your project
platform :ios, '10.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.delete 'IPHONEOS_DEPLOYMENT_TARGET'
       end
    end
  end

我们现在有点坚持。对可能发生的事情有任何想法吗?有人遇到过同样的错误吗?

更新:2021-07-19 - 1

深入研究,我进入xcode_backend.sh无法运行带有退出代码 1 的颤振命令。命令如下:

flutter assemble --no-version-check --output=<path>/app/app/build/ios/Debug-dev-iphoneos/ \
-dTargetPlatform=ios \
-dTargetFile=<path>/app/app/lib/main_dev.dart \
-dBuildMode=debug \
-dIosArchs=arm64 \
-dSdkRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk \
-dSplitDebugInfo= \
-dTreeShakeIcons=false \
-dTrackWidgetCreation=true \
-dDartObfuscation=false \
-dEnableBitcode= \
-dCodesignIdentity=xxxx \
--ExtraGenSnapshotOptions= \
--DartDefines=xx,xx \
--ExtraFrontEndOptions= \
debug_ios_bundle_flutter_assets

标签: iosxcodefirebaseflutter

解决方案


我找到了解决此问题的方法。Flutter 2.0 在 ios 方面有一些突破性的变化,并且在这个意义上真的很糟糕的默认调试功能。确保在构建期间在 xcode_backend.sh 中启用了详细信息(此处)。

关于我的错误更具体,颤振组装返回此错误:

Target debug_ios_bundle_flutter_assets failed: FileSystemException: Cannot open file, path = '<path>/app/app/ios/Flutter/AppFrameworkInfo.plist' (OS Error: No such file or directory, errno = 2)

只需添加 AppFrameworkInfo.plist 即可:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>CFBundleDevelopmentRegion</key>
  <string>en</string>
  <key>CFBundleExecutable</key>
  <string>App</string>
  <key>CFBundleIdentifier</key>
  <string>io.flutter.flutter.app</string>
  <key>CFBundleInfoDictionaryVersion</key>
  <string>6.0</string>
  <key>CFBundleName</key>
  <string>App</string>
  <key>CFBundlePackageType</key>
  <string>FMWK</string>
  <key>CFBundleShortVersionString</key>
  <string>1.0</string>
  <key>CFBundleSignature</key>
  <string>????</string>
  <key>CFBundleVersion</key>
  <string>1.0</string>
  <key>MinimumOSVersion</key>
  <string>8.0</string>
</dict>
</plist>

无论如何,推荐的方法是删除您的 ios 文件夹(或在迁移期间将其移动到 ios.old)并重新创建它 running flutter create -i swift


推荐阅读