vscode 中flutter找不到模拟器
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vscode 中flutter找不到模拟器相关的知识,希望对你有一定的参考价值。
参考技术A 记录一个学习flutter中的小问题。我使用的是mac电脑开始学习flutter。在使用vs code中突然找不到模拟器了。 直接走web调试或者真机调试,在vscode上也找不到选择模拟器的地方。
查找问题:
1.执行flutter doctor。发现找不到fluterr的命令了。很明显是flutter的环境变量没设置进去。很神奇明明前面一直在使用。
2.打印环境变量
果然没有。突然记起我安装fluter的时候图方便直接执行的
来添加环境变量的。flutter官网上有说明这个只能暂时针对当前命令行窗口设置PATH环境变量。然后还是老老实实的去~/.bash_profile中设置了环境变量。果然运行良好。
找不到文件“Flutter/Flutter.h”致命错误 Flutter 2.5.1
【中文标题】找不到文件“Flutter/Flutter.h”致命错误 Flutter 2.5.1【英文标题】:File not found 'Flutter/Flutter.h' Fatal Error Flutter 2.5.1 【发布时间】:2021-11-20 23:14:16 【问题描述】:我最近买了一台新的 M1 Mac 并更新了 Flutter 版本(到 Flutter v2.5.1)和 Xcode 版本(到 Xcode 13.0)(不是一个明智的决定)。我尝试在 iOS 模拟器上运行,但遇到错误“未找到 Flutter/Flutter.h”文件”。我已将所有依赖项更新到最新版本。我尝试删除“iOS”文件夹并进行颤振创建,但这又让我回到了同样的错误。我尝试了以前帖子中针对同一问题的所有推荐解决方案,但均无济于事(即删除 Flutter.podspec,删除 pod file.lock)。我也没有从主分支切换到稳定(我一直处于稳定状态)。我已经尝试了几乎所有的解决方案,但没有一个为我解决了这个问题。谢谢你的帮助。
(旁注:我尝试在 Android 模拟器上运行,除 GoogleSignIn 外一切正常)
ravipenikelapati@Ravis-MBP Creww-App % flutter doctor -v
[✓] Flutter (Channel stable, 2.5.1, on macOS 11.6 20G165 darwin-arm, locale en-US)
• Flutter version 2.5.1 at /Users/ravipenikelapati/FlutterDev/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision ffb2ecea52 (11 days ago), 2021-09-17 15:26:33 -0400
• Engine revision b3af521a05
• Dart version 2.14.2
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/ravipenikelapati/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Users/ravipenikelapati/Downloads/Android
Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.0, Build version 13A233
• CocoaPods version 1.11.2
[✗] 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 (version 2020.3)
• Android Studio at /Users/ravipenikelapati/Downloads/Android Studio.app/Contents
• Flutter plugin can be installed from:
???? https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
???? https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
[✓] VS Code (version 1.60.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.26.0
[✓] Connected device (1 available)
• iPhone 13 (mobile) • 21F1617B-4715-4EC9-B15D-2DD55519E7D3 • ios •
com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
! Doctor found issues in 1 category.
Flutter 错误输出:
Launching lib/main.dart on iPhone 13 in debug mode...
lib/main.dart:1
Xcode build done. 8.2s
Failed to build iOS app
Error output from Xcode build:
↳
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device
platform:iOS Simulator, id:92375C2D-F6DE-4B7F-869B-FD16EE37BC0A, OS:15.0, name:iPad (9th generation)
platform:iOS Simulator, id:64D26107-BE18-4ED7-9238-4BF3DADA2301, OS:15.0, name:iPad Air (4th generation)
platform:iOS Simulator, id:BA3609E7-7F27-4440-879C-3DC65D18E838, OS:15.0, name:iPad Pro (9.7-inch)
platform:iOS Simulator, id:FE7AADF2-E380-4139-B1AF-004029F33C29, OS:15.0, name:iPad Pro (11-inch) (3rd generation)
platform:iOS Simulator, id:8FA3DEC3-3F12-47E3-8490-A4E4786A8C77, OS:15.0, name:iPad Pro (12.9-inch) (5th generation)
platform:iOS Simulator, id:8DE0D105-9E50-4DA6-BD87-DA381C590E8A, OS:15.0, name:iPad mini (6th generation)
platform:iOS Simulator, id:89DA58EA-E4AA-4BD2-948B-76C6F7613CE6, OS:15.0, name:iPhone 8
platform:iOS Simulator, id:3FB087A2-4DEA-4972-A5C0-6B74CB4B3D4C, OS:15.0, name:iPhone 8 Plus
platform:iOS Simulator, id:34C05C4F-ABF4-4D2C-8CFB-AB9D9F81496A, OS:15.0, name:iPhone 11
platform:iOS Simulator, id:E5EDE7A3-B3FA-4864-ACC3-E7FA1F8C689B, OS:15.0, name:iPhone 11 Pro
platform:iOS Simulator, id:ED158108-0E9A-4AD4-BA76-14FB4B62AC5A, OS:15.0, name:iPhone 11 Pro Max
platform:iOS Simulator, id:DB6EEF02-9DBC-4F5D-8FD5-679169A0EFA7, OS:15.0, name:iPhone 12
platform:iOS Simulator, id:E122CD45-51EF-45FE-8B51-D5798606BF7A, OS:15.0, name:iPhone 12 Pro
platform:iOS Simulator, id:7415DE00-6657-4F0F-BB38-8EC58323F6FF, OS:15.0, name:iPhone 12 Pro Max
platform:iOS Simulator, id:5487FAA8-0B72-4477-AD3F-F3F8DB3DDD04, OS:15.0, name:iPhone 12 mini
platform:iOS Simulator, id:21F1617B-4715-4EC9-B15D-2DD55519E7D3, OS:15.0, name:iPhone 13
platform:iOS Simulator, id:D3BA25C2-DEE0-4E5E-BFA5-B5C3708809E3, OS:15.0, name:iPhone 13 Pro
platform:iOS Simulator, id:089C91CB-D751-4AE0-9448-2FCAB72C7A12, OS:15.0, name:iPhone 13 Pro Max
platform:iOS Simulator, id:F1A4CE57-775E-4753-98EB-EDBFF71FCE8C, OS:15.0, name:iPhone 13 mini
platform:iOS Simulator, id:C20EA51A-A417-4464-BD51-CD58F0C012E3, OS:15.0, name:iPhone SE (2nd generation)
platform:iOS Simulator, id:36BC4107-F7CA-4BA7-ADF7-60D2DD0F0E89, OS:15.0, name:iPod touch (7th generation)
platform:macOS, arch:arm64, variant:Designed for [iPad,iPhone], id:00008103-001A28A41E53001E
platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device
** BUILD FAILED **
Xcode's output:
↳
In file included from /Users/ravipenikelapati/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.12/ios/Classes/FLTURLLauncherPlugin.m:7:
/Users/ravipenikelapati/FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-6.0.12/ios/Classes/FLTURLLauncherPlugin.h:5:9: fatal error: 'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>
^~~~~~~~~~~~~~~~~~~
1 error generated.
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in parallel
Could not build the application for the simulator.
Error launching application on iPhone 13.
Exited (sigterm)
【问题讨论】:
我遇到了同样的问题。你找到解决办法了吗? 我也没有找到解决方案,以前的解决方案都没有对我有用 我正在为同样的问题而苦苦挣扎,应用程序适用于 Android,但不适用于 IOS。您是否找到任何解决方案,因为我在过去 9 小时内尝试了所有方法并尝试了所有方法 【参考方案1】:发生这种情况是因为它找不到 flutter.h(为 iOS 生成的头文件)。
用flutter clean
清理项目后尝试运行pod install
【讨论】:
我已经尝试了多次,但仍然遇到与上述类似的问题。 我已经尝试过这个解决方案,但这并没有为我解决问题 我认为您必须使用flutter create .
命令在现有项目中重新创建生成的文件
我也尝试过这条路线,方法是删除 ios 文件夹并调用 flutter create 。在根目录中。那没有解决它
@RaviPenikelapati 您能否检查并验证新答案?谢谢【参考方案2】:
作为另一个答案发布,因为这似乎是可能的答案并帮助其他人看到
这应该很有效:
-
cd 进入 ios 目录 (
cd ios
)
pod deintegrate
rm Flutter/Flutter.podspec
rm podfile.lock
flutter clean
flutter run
【讨论】:
也试过了,还是说 Fatal Error: File not found 'Flutter/Flutter.h'【参考方案3】:这对我有用:
在 Podfile 中: 替换
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
end
end
end
由
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
然后在 Xcode 和 Pods 中打开 iOS 文件,对于每个 Target,在 Build Settings 中,将部署目标设置为 11(也许 9 就足够了)
【讨论】:
以上是关于vscode 中flutter找不到模拟器的主要内容,如果未能解决你的问题,请参考以下文章