flutter 各种报错收集及处理(持久更新。。。)
一直以来没有写关于flutter 环境配置报错相关的文章,刚刚最近遇到了,今天我们就来分享相关的各种报错及处理步骤
回到正题
报错一:Command PhaseScriptExecution failed with a nonzero exit code ...
当你遇到下面的报错,请优先考虑升级flutter版本!请优先考虑升级flutter版本!请优先考虑升级flutter版本!
(这是血泪史的总结:不管你怎么去配置环境,尝试各种方式去修复这种的错误,有可能花费几天的时间去修复这个报错,最终还是解决不了的。)
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
完整的报错内容大概如下面的内容
Launching lib/main.dart on iPhone 13 in debug mode...
Running Xcode build...
Xcode build done. 11.0s
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:32DEE5DB-A650-46E5-BD94-E90C28C32779, OS:15.2, name:iPad (9th generation) }
{ platform:iOS Simulator, id:D9C9F5A1-6574-4B80-803A-6613EC98D51C, OS:13.0, name:iPad Air (3rd generation) }
{ platform:iOS Simulator, id:9C2A9166-F868-4D4A-8A97-8787EBA1CB89, OS:15.2, name:iPad Air (4th generation) }
{ platform:iOS Simulator, id:3DA7051E-6385-44AA-ACF3-B9587A99EEB1, OS:13.0, name:iPad Pro (9.7-inch) }
{ platform:iOS Simulator, id:A9BB42E9-C1E2-4D57-8028-4EC1283FC607, OS:15.2, name:iPad Pro (9.7-inch) }
{ platform:iOS Simulator, id:E7A825AF-1D32-43A3-A50D-7511DDEEBCFC, OS:13.0, name:iPad Pro (11-inch) (1st generation) }
{ platform:iOS Simulator, id:598EAD49-BC67-40AB-8586-83E0DC334E49, OS:15.2, name:iPad Pro (11-inch) (3rd generation) }
{ platform:iOS Simulator, id:21309FD1-E1B7-424B-B924-8CD6453E0B72, OS:13.0, name:iPad Pro (12.9-inch) (3rd generation) }
{ platform:iOS Simulator, id:EFDA4390-E597-4C07-9131-279C38E24CEA, OS:15.2, name:iPad Pro (12.9-inch) (5th generation) }
{ platform:iOS Simulator, id:59AC9A72-AAA1-418F-8F85-6A3F827A53A5, OS:15.2, name:iPad mini (6th generation) }
{ platform:iOS Simulator, id:5FAB1C72-556C-4EA9-8AE9-0219E2A15714, OS:13.0, name:iPhone 8 }
{ platform:iOS Simulator, id:B5C73116-515F-44FC-BF86-33091FD3A4F3, OS:15.2, name:iPhone 8 }
{ platform:iOS Simulator, id:AE09A068-2A15-4D95-B0E6-A04513749C3A, OS:13.0, name:iPhone 8 Plus }
{ platform:iOS Simulator, id:90316056-A49A-4277-AF4D-83A14C7DDF44, OS:15.2, name:iPhone 8 Plus }
{ platform:iOS Simulator, id:1E16F10E-BF53-4707-BF80-2DDC9E7E1730, OS:13.0, name:iPhone 11 }
{ platform:iOS Simulator, id:5E6560C6-AB42-4B4C-9D32-C37F90857684, OS:15.2, name:iPhone 11 }
{ platform:iOS Simulator, id:EA1EBAF8-095F-4CAD-B8CB-3EE686C1F801, OS:13.0, name:iPhone 11 Pro }
{ platform:iOS Simulator, id:E541F288-C448-4556-8A5D-95518B34C202, OS:15.2, name:iPhone 11 Pro }
{ platform:iOS Simulator, id:F46DFE34-DDD9-4B35-8D33-3E39FA792C8D, OS:13.0, name:iPhone 11 Pro Max }
{ platform:iOS Simulator, id:27F3907E-A0BC-452B-961C-96893986ACF2, OS:15.2, name:iPhone 11 Pro Max }
{ platform:iOS Simulator, id:D9021782-DB65-427F-955E-F91FCCE0CF3B, OS:15.2, name:iPhone 12 }
{ platform:iOS Simulator, id:4164A267-20A5-4D00-A085-9B3999C2A468, OS:15.2, name:iPhone 12 Pro }
{ platform:iOS Simulator, id:5B180C3B-0185-41F0-8AC6-EA5C79381E07, OS:15.2, name:iPhone 12 Pro Max }
{ platform:iOS Simulator, id:D3E82E25-EC46-4090-AADF-CBB34FA7BCF7, OS:15.2, name:iPhone 12 mini }
{ platform:iOS Simulator, id:0A544E75-178C-4E92-8FD3-D99FB8E6B525, OS:15.2, name:iPhone 13 }
{ platform:iOS Simulator, id:433C1A43-C45A-453B-AC87-1AF648D6D1F2, OS:15.2, name:iPhone 13 Pro }
{ platform:iOS Simulator, id:CCEBBCBC-9391-4679-B1AF-DBA663129323, OS:15.2, name:iPhone 13 Pro Max }
{ platform:iOS Simulator, id:42EF69A2-BDA6-4D28-B376-D17DCAB4A17E, OS:15.2, name:iPhone 13 mini }
{ platform:iOS Simulator, id:6CEAACC2-6C70-4BE5-A296-26CC21BA0449, OS:15.2, name:iPhone SE (2nd generation) }
{ platform:iOS Simulator, id:7D9C4631-4C2C-4B50-BE8C-0956429AA897, OS:15.2, name:iPod touch (7th generation) }
{ platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
** BUILD FAILED **
Xcode's output:
↳
../../../.pub-cache/hosted/pub.flutter-io.cn/get-4.6.1/lib/get_navigation/src/root/get_cupertino_app.dart:252:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/Applications/flutter/packages/flutter/lib/src/cupertino/app.dart:189:9: Context: Found this candidate, but the arguments don't match.
const CupertinoApp.router({
^^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/get-4.6.1/lib/get_navigation/src/root/get_cupertino_app.dart:292:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/Applications/flutter/packages/flutter/lib/src/cupertino/app.dart:145:9: Context: Found this candidate, but the arguments don't match.
const CupertinoApp({
^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/get-4.6.1/lib/get_navigation/src/root/get_material_app.dart:275:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/Applications/flutter/packages/flutter/lib/src/material/app.dart:217:9: Context: Found this candidate, but the arguments don't match.
const MaterialApp.router({
^^^^^^^^^^^^^^^^^^
../../../.pub-cache/hosted/pub.flutter-io.cn/get-4.6.1/lib/get_navigation/src/root/get_material_app.dart:322:17: Error: No named parameter with the name 'useInheritedMediaQuery'.
useInheritedMediaQuery: useInheritedMediaQuery,
^^^^^^^^^^^^^^^^^^^^^^
/Applications/flutter/packages/flutter/lib/src/material/app.dart:166:9: Context: Found this candidate, but the arguments don't match.
const MaterialApp({
^^^^^^^^^^^
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
Could not build the application for the simulator.
Error launching application on iPhone 13.
修复步骤如下
1.先看一下当前的版本
Justin-Mac-mini:ios zhangzheng$ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.3, on macOS 12.1 21C52 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Community Edition (version 2021.2.2)
[✓] VS Code (version 1.63.2)
[✓] Connected device (3 available)
2.强制升级flutter版本
flutter upgrade --force
3.如果升级很顺利,请忽略此步骤,如果升级遇到如下报错, 有可能是你的电脑使用了“梯子”,请关闭你电脑里面的翻墙软件,再执行升级命令
ProcessException: Process exited abnormally:
fatal: 无法访问 'https://github.com/flutter/flutter.git/':LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
Command: git fetch --tags
4.升级完成后,可以再看一下当前flutter版本flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.8.1, on macOS 12.1 21C52 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Community Edition (version 2021.2.2)
[✓] VS Code (version 1.63.2)
[✓] Connected device (3 available)
报错二:fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h>
如果按照上面的步骤,已经把flutter版本升级到最新版本,这个时候,你尝试把工程代码运行起来,有可能就会遇到下面的报错
In file included from /Users/zhangzheng/.pub-cache/hosted/pub.flutter-io.cn/package_info_plus-1.3.0/ios/Classes/FLTPackageInfoPlusPlugin.m:5:
/Users/zhangzheng/.pub-cache/hosted/pub.flutter-io.cn/package_info_plus-1.3.0/ios/Classes/FLTPackageInfoPlusPlugin.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 dependency order
修复步骤如下
1.找到工程文件的ios目录,直接删除Podfile
,Podfile.lock
这2个文件
2.在Android Studio 的Terminal里面,
flutter clean
一下,重新run工程,flutter 会自动生成对应的Podfile
,Podfile.lock
,不出意外的话,工程就能正常跑起来了。image.png
最终结果如下:
image.png
最后增加一些其他报错
其他报错一: Try replacing 'com.example' with your signing id in Xcode:
It appears that your application still contains the default signing identifier.
Try replacing 'com.example' with your signing id in Xcode:
open ios/Runner.xcworkspace
Encountered error while building for device.
Justin-Mac-mini:ios zhangzheng$
修复步骤如下
image.png image.png其他报错二: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'Flutter' from project 'Pods')
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
/Users/zhangzheng/Desktop/ble_teleprompter/teleprompter/ios/Pods/Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'Flutter' from project 'Pods')
修复步骤如下: 把podfile文件的最后面替换一下
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
end
end
end
image-20220112100825655.png
其他报错三:dependency were found, but they required a higher minimum deployment target
[!] CocoaPods could not find compatible versions for pod "reactive_ble_mobile":
In Podfile:
reactive_ble_mobile (from `.symlinks/plugins/reactive_ble_mobile/ios`)
Specs satisfying the `reactive_ble_mobile (from `.symlinks/plugins/reactive_ble_mobile/ios`)` dependency were found, but they required a higher minimum deployment target.
修复步骤如下:
1.点击一下Finder
2.cmd + shift +g,打开路径弹框
- 把
/Users/xxx/.pub-cache/hosted/pub.flutter-io.cn/xxx/ios/
,拷贝到弹框中,回车一下
3.png
4.打开xxx.podspec
文件,看一下,要求的iOS的最低版本
5.把flutter工程里面ios工程 里面的podfile打开,把ios支持版本改为上面要求的最低版本
5.png 5.png
6.重新
pod install
,如果中间有失败,多重试就可以把所有依赖库安装完6.png
6.png
其他报错四:版本依赖冲突
假设你的项目同时引用了some_package和other_package两个包,而这两个包又同时引用了collection这个包,若这两个包引用了不同的collection版本就会造成冲突。
some_package的依赖如下:
dependencies:
collection: '1.8.1'
other_package的依赖如下:
dependencies:
collection: '1.9.0'
修复步骤如下:
可以通过强制覆盖的方法,dependency_overrides:
,在我们的项目中指定一个版本,如下
dependencies:
some_package:
another_package:
dependency_overrides:
collection: '1.8.2'
下面的报错,原因跟上面提到的是一样的
Because every version of esp_provisioning depends on protobuf ^1.0.1 and every version of barcode_scan2 depends on protobuf ^2.0.0, esp_provisioning is incompatible with barcode_scan2.
So, because gateway_x5_factory_tool depends on both barcode_scan2 ^4.0.0 and esp_provisioning ^1.0.0+6, version solving failed.
pub get failed (1; So, because gateway_x5_factory_tool depends on both barcode_scan2 ^4.0.0 and esp_provisioning ^1.0.0+6, version solving failed.)
同理,我们可以通过强制覆盖的方法,来解决此依赖版本冲突的报错
dependency_overrides:
protobuf: '2.0.0'
其他报错五:A problem occurred configuring project ':app_installer'.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app_installer'.
> Could not resolve all artifacts for configuration ':app_installer:classpath'.
> Could not download kotlin-stdlib-common-1.3.61.jar (org.jetbrains.kotlin:kotlin-stdlib-common:1.3.61)
> Could not get resource 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-common/1.3.61/kotlin-stdlib-common-1.3.61.jar'.
> Could not GET 'https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-common/1.3.61/kotlin-stdlib-common-1.3.61.jar'.
> Connection reset
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2m 21s
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download...
Running Gradle task 'assembleDebug'...
修复步骤如下: flutter工程=>android=>build.gradle,在中间位置加上mavenCentral()
,
image.png
其他报错六:Execution failed for task ':wifi:generateDebugRFile'
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':wifi:generateDebugRFile'.
> Could not resolve all files for configuration ':wifi:debugCompileClasspath'.
> Could not download vectordrawable-1.0.1.aar (androidx.vectordrawable:vectordrawable:1.0.1)
> Could not get resource 'https://dl.google.com/dl/android/maven2/androidx/vectordrawable/vectordrawable/1.0.1/vectordrawable-1.0.1.aar'.
> Could not GET 'https://dl.google.com/dl/android/maven2/androidx/vectordrawable/vectordrawable/1.0.1/vectordrawable-1.0.1.aar'.
> Connection reset
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2m 59s
[!] Gradle threw an error while downloading artifacts from the network. Retrying to download...
Running Gradle task 'assembleDebug'...
其他报错七:Build failed due to use of deprecated Android v1 embedding'
The detected reason was:
/Users/zhangzheng/Desktop/learn/flutter_test_demos/android/app/src/main/AndroidManifest.xml uses `android:name="io.flutter.app.FlutterApplication"`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Build failed due to use of deprecated Android v1 embedding.
修复步骤如下:
1.首先根据提示的路径找到manifest,安卓app的配置文件
2.删除name属性
android:name="io.flutter.app.FlutterApplication"
image.png
3.检查activity标签下有没有下面的代码,如果没有的话,就将下面代码到activity标签下
<meta-data android:name="flutterEmbedding" android:value="2"/>
image.png其他报错八: Your project requires a newer version of the Kotlin Gradle plugin
│ [!] Your project requires a newer version of the Kotlin Gradle plugin. │
│ Find the latest version on https://kotlinlang.org/docs/gradle.html#plugin-and-versions, then │
│ update /Users/zhangzheng/Desktop/SVN/AndroidStudio/configx5gateway_flutter/android/build.gradle: │
│ ext.kotlin_version = '<latest-version>'
修复步骤如下:
找到文件 工程名/android/build.gradle
,把鼠标放在$kotlin_version
,过一会就有提示需要的最新版本,如下图
其他报错九: The current Gradle version 6.7 is not compatible with the Kotlin Gradle plugin. Please use Gradle 6.7.1 or newer, or the previous version of the Kotlin plugin.
image.png
修复步骤如下:
找到文件 工程名/android/gradle/wrapper/gradle-wrapper.properties
,把gradle的版本改为它要求的版本6.7.1或者是更高版本
其他报错十:Exception: Error running pod install
Error output from CocoaPods:
↳
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 4085k 100 4085k 0 0 381k 0 0:00:10 0:00:10 --:--:-- 507k
Cloning into '/var/folders/v5/hdsqshn144sb27g0k0shfbym0000gn/T/d20220706-35736-qq2jls'...
error: RPC failed; curl 56 LibreSSL SSL_read: error:02FFF036:system library:func(4095):Connection reset by peer, errno 54
fatal: early EOF
fatal: fetch-pack: invalid index-pack output
[!] Automatically assigning platform `iOS` with version `10.0` on target `Runner` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
Exception: Error running pod install
修复步骤如下:
- 打开终端Terminal
-
cd 到iOS工程文件夹的路径,如下图
image.png
- 手动
pod install
一下,就不在flutter工程去pod install了(如果安装过程失败了,就多尝试几次pod install
,祝君好运~)
其他报错十一:Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI:
adb: failed to install /xxx/xxx/xxx/build/app/outputs/flutter-apk/app.apk: Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED: Failed parse during installPackageLI: /data/app/vmdl279474045.tmp/base.apk (at Binary XML file line #61): com.smartowon.www.owoncare.MainActivity: Targeting S+ (version 31 and above) requires that an explicit value for android:exported be defined when intent filters are present]
修复步骤如下:
在 Android 12 中包含 <intent-filter> 的 activity 、 service 或 receiver 必须为这些应用组件显示声明 android:exported 属性
-
在activity中增加
image.png -
在service中增加
image.png
也可以参考如下文章:
https://www.jianshu.com/p/c0472c7ed286
https://juejin.cn/post/7043582179103735821
结尾
今天的分享至此接近尾声喽,小伴们,觉得有点用的话,或者已经看到这里面来的请点赞加关注吧~~ 后续分享更多有关flutter的文章。如果有疑问的话,欢迎在下方留言~ 新年好运!!!!