Flutter 项目无法在 Mac M1 上构建 [英] Flutter project failing to build on Mac M1

查看:42
本文介绍了Flutter 项目无法在 Mac M1 上构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近买了一本带有 M1 芯片的新 Mac 书,但在两者之间遇到了巨大的问题构建中的 Flutter 和 Firebase.我会列出 Flutter 错误日志和 Xcode 错误日志.

I have recently bought a new Mac book with the M1 chip and faced huge issues between Flutter and Firebase in building. I will list both the Flutter error log and Xcode error log.

注意:我正在 Flutter 频道 Master

Note: I'm building on Flutter channel Master

颤动错误日志:

    Launching lib/main.dart on iPod touch (7th generation) in debug mode...
    Xcode build done.                                           69.1s
    Failed to build iOS app

Xcode 构建的错误输出:

Error output from Xcode build:

objc[30795]: Class AMSupportURLConnectionDelegate is implemented in both ?? (0x1fe91f8f0) and ?? (0x1189402b8). One of the two will be used. Which one is undefined.
objc[30795]: Class AMSupportURLSession is implemented in both ?? (0x1fe91f940) and ?? (0x118940308). One of the two will be used. Which one is undefined.
** BUILD FAILED **

Xcode 的输出:

/Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.7+1/ios/Classes/FLTImagePickerPlugin.m:141:20: warning: 'UIAlertView' is deprecated: first deprecated in iOS 9.0 - UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead [-Wdeprecated-declarations]
    [[[UIAlertView alloc] initWithTitle:@"Error"
                   ^
In module 'UIKit' imported from /Volumes/Sub/Flutter-Projects/test-project/test_project_app_v2/test_app_2/ios/Pods/Target Support Files/image_picker/image_picker-prefix.pch:2:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAlertView.h:27:12: note: 'UIAlertView' has been explicitly marked deprecated here
@interface UIAlertView : UIView
           ^
1 warning generated.
/Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.7+1/ios/Classes/FLTImagePickerPhotoAssetUtil.m:17:44: warning: 'UIImagePickerControllerReferenceURL' is deprecated: first deprecated in iOS 11.0 - Will be removed in a future release, use PHPicker. [-Wdeprecated-declarations]
  NSURL *referenceURL = [info objectForKey:UIImagePickerControllerReferenceURL];
                                           ^
In module 'UIKit' imported from /Volumes/Sub/Flutter-Projects/test-project/test_project_app_v2/test_app_2/ios/Pods/Target Support Files/image_picker/image_picker-prefix.pch:2:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIImagePickerController.h:62:51: note: 'UIImagePickerControllerReferenceURL' has been explicitly marked deprecated here
UIKIT_EXTERN UIImagePickerControllerInfoKey const UIImagePickerControllerReferenceURL API_DEPRECATED("Will be removed in a future release, use PHPicker.", ios(4.1, 11.0)) API_UNAVAILABLE(tvos); // an NSURL that references an asset in the AssetsLibrary framework
                                                  ^
/Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.7+1/ios/Classes/FLTImagePickerPhotoAssetUtil.m:21:47: warning: 'fetchAssetsWithALAssetURLs:options:' is deprecated: first deprecated in iOS 11 - Will be removed in a future release [-Wdeprecated-declarations]
  PHFetchResult<PHAsset *> *result = [PHAsset fetchAssetsWithALAssetURLs:@[ referenceURL ]
                                              ^
In module 'Photos' imported from /Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker-0.6.7+1/ios/Classes/FLTImagePickerPhotoAssetUtil.h:6:
/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/System/Library/Frameworks/Photos.framework/Headers/PHAsset.h:74:1: note: 'fetchAssetsWithALAssetURLs:options:' has been explicitly marked deprecated here
+ (PHFetchResult<PHAsset *> *)fetchAssetsWithALAssetURLs:(NSArray<NSURL *> *)assetURLs options:(nullable PHFetchOptions *)options API_DEPRECATED("Will be removed in a future release", ios(8, 11), tvos(8, 11)) API_UNAVAILABLE(macos);
^
2 warnings generated.
1 warning generated.
error: the following command failed with exit code 0 but produced no further output
CompileC /Users/wissamboughannam/Library/Developer/Xcode/DerivedData/Runner-awkucyxpawezvvfjchbivjxuwsah/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/file_picker.build/Objects-normal/x86_64/FilePickerPlugin.o /Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/file_picker-1.4.2/ios/Classes/FilePickerPlugin.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
/Volumes/Sub/Flutter-Projects/test-project/test_project_app_v2/test_app_2/ios/Pods/FirebaseCore/FirebaseCore/Sources/FIRLogger.m:58:28: warning: this old-style function definition is not preceded by a prototype [-Wstrict-prototypes]
void FIRLoggerInitializeASL() {
                           ^
/Volumes/Sub/Flutter-Projects/test-project/test_project_app_v2/test_app_2/ios/Pods/FirebaseCore/FirebaseCore/Sources/FIRLogger.m:101:20: warning: this old-style function definition is not preceded by a prototype [-Wstrict-prototypes]
void FIRResetLogger() {
                   ^
2 warnings generated.

/Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:259:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/Users/wissamboughannam/Developer/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        ? context.inheritFromWidgetOfExactType(type) as InheritedProvider<T>
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:260:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/Users/wissamboughannam/Developer/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorInheritedElementForWidgetOfExactType'.
        : context.ancestorInheritedElementForWidgetOfExactType(type)?.widget
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
note: Removed stale file

至于 Xcode 的错误日志:

As for the Error log from Xcode:

/Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:259:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/Users/wissamboughannam/Developer/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        ? context.inheritFromWidgetOfExactType(type) as InheritedProvider<T>
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/Users/wissamboughannam/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:260:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/Users/wissamboughannam/Developer/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorInheritedElementForWidgetOfExactType'.
        : context.ancestorInheritedElementForWidgetOfExactType(type)?.widget

这是主要错误,有很多警告,但我不确定它们是否导致构建失败.

This is the main error, there were many warning, but I'm not sure if they're causing the build failure.

运行flutter doctor结果:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 2.1.0-11.0.pre.227, on macOS 11.1 20C69 darwin-arm, locale en-SA)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.54.1)
[✓] Connected device (2 available)

• No issues found!

推荐答案

正如我们所知,m1 mac 在基于 arm 的处理器上运行,因此很少需要基于此构建可可豆荚和 ffi 之类的东西.经过长时间的研究,我想出了几个步骤,这些步骤肯定会在您每次坚持为 m1 mac 构建 xcode flutter 应用程序时有所帮助.

As we know that m1 mac runs on arm based processor and thus few things like cocoa pods and ffi needs to be build based on that. After a long research i came up with few steps which will definitely help everytime you stuck with xcode flutter application build for m1 mac.

  • sudo gem 安装 cocoapods
  • sudo gem install ffi
  • arch -x86_64 sudo gem install cocoapods -n/usr/local/bin
  • sudo gem install cocoapods -n/usr/local/bin
  • sudo arch -x86_64 gem install ffi

#更新仓库

  • arch -x86_64 pod install --repo-update
  • 扑通干净
  • flutter build ios
  • arch -x86_64 pod 安装

这篇关于Flutter 项目无法在 Mac M1 上构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆