flutter常见各种报错

2,391 阅读5分钟

1.flutter项目,Android studio中运行出来了,但是在Xcode中打开会崩溃

Android studio 已经可以安卓跑起来了,但是Xcode打开iOS不行

报错如下,代码截了部分

2021-05-26 09:59:09.109871+0800 Runner[2773:375299] Metal API Validation Enabled

2021-05-26 09:59:09.499726+0800 Runner[2773:375480] [VERBOSE-2:shell.cc(103)] Dart Error: Can't load Kernel binary: Invalid kernel binary format version.

2021-05-26 09:59:09.500086+0800 Runner[2773:375480] [VERBOSE-2:dart_isolate.cc(171)] Could not prepare isolate.

2021-05-26 09:59:09.500889+0800 Runner[2773:375480] [VERBOSE-2:runtime_controller.cc(415)] Could not create root isolate.

2021-05-26 09:59:09.501004+0800 Runner[2773:375480] [VERBOSE-2:shell.cc(588)] Could not launch engine with configuration.

2021-05-26 09:59:09.605892+0800 Runner[2773:375491] flutter: Observatory listening on http://127.0.0.1:52644/yx3crbYDJgQ=/

2021-05-26 09:59:10.075028+0800 Runner[2773:375473] [] tcp_input [C1.1:3] flags=[R] seq=258277982, ack=1003213000, win=0 state=LAST_ACK rcv_nxt=258277982, snd_una=367767513

2021-05-26 09:59:10.075340+0800 Runner[2773:375473] [] tcp_input [C1.1:3] flags=[R] seq=258277982, ack=1003213000, win=0 state=CLOSED rcv_nxt=258277982, snd_una=367767513

2021-05-26 09:59:10.240940+0800 Runner[2773:375472] [] tcp_input [C2.1:3] flags=[R] seq=1611108597, ack=4246611532, win=0 state=LAST_ACK rcv_nxt=1611108597, snd_una=3339256281

2021-05-26 09:59:10.249862+0800 Runner[2773:375472] [] tcp_input [C2.1:3] flags=[R] seq=1611108597, ack=4246611532, win=0 state=CLOSED rcv_nxt=1611108597, snd_una=3339256281

2021-05-26 09:59:14.945327+0800 Runner[2773:375299] Preloading CNContactViewController

flutter clean

flutter pub get

cd ios

pod install

注意:Xcode打开flutter项目是打开iOS下的 .xcworkspace,而不是上面的.xcodeproj

image.png

还不行,看下面

image.png 这个是个坑,不知道为什么,长按程序坞Xcode,标识点击项目就可以打开

以上基本上都能打开,如果,如果,看下面……

如果是旧项目拿过来改的,上面操作还是不行的话,有一个骚操作:过程如下

解决办法:1. 删掉整个iOS 部分,然后 flutter create 项目名 (这里就是h3yunapp),

补充一下:

如果 flutter create . 它的执行是按照 外层文件夹路径来的

image.png

新项目的话 退出应用 修改文件夹名字(英文字母全小写,不能有其他特殊字符 如 -)

过程就是新建一个项目把新项目的ios部分替换掉,应该能打开

2.把iOS替换过来,然后再git 对比之前更改的文件,基本上都是撤回来

注意:刚刚替换的时候 看看能不能Xcode打开,我这是可以的 猜测应该是某些看不到的文件已经更改了

2.Flutter编译时出错:could not find included file 'Pods/Target Support Files/Pods-Runner/Pods-Runner.debu...

解决办法如下:

  • 1、保证在下面根目录下执行下面:flutter clean
  • 2、然后cd到ios目录执行下面:cd ios
  • 3、最后执行这一步:pod install
  • 4、运行发现问题解决

3.The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods install

方案一: command+Q 退出 Xcode,重新执行pod install,之后再重新打开Xcode运行。

正常 方案一: 即可解决问题.

不行的话 参考该博客博客其他方法

blog.csdn.net/grl18840839…

4.Your Flutter application is created using an older version of the Android embedding. 问题解决

将下方标签添加至 AndroidManifest.xml 文件的 activity 标签下(android/app/src/)

5. Execution failed for task ‘:app:lintVitalRelease’. > Lint found fatal errors while assembling a release target.

原因:在通过AndroidStudio 工具生成一个带签名的API时报错,具体错误如下: 解决办法:

1.在 项目\app\build.gradle 文件中 添加 如下代码

android { 
    lintOptions { 
        checkReleaseBuilds false 
            // Or, if you prefer, you can continue to check for errors in release builds,          
            // but continue the build even when errors are found: 
       abortOnError false
       } 
   }
  1. 点击Build>Clean Project 清理下工程,然后点击Build>Rebuild Project 重新构建下工程

image.png

6.Suggestion: use a compatible library with a minSdk of at most 16,or increase this project's minSdk version to at least 21,or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)

参考文章:

blog.csdn.net/weixin_3763…

原因

造成这种问题的原因是自己项目的minSdkVersion比三方SDK的的minSdkVersion低,即版本不一致导致的。

解决办法

其实在上面的日志中也给出了这种问题的三种解决方案:

1.Suggestion: use a compatible library with a minSdk of at most 16:将三方库的minSdkVersion降低,这种方案一般是不可行,我们自己无法修改对方的SDK的minSdkVersion。

2.increase this project's minSdk version to at least 19:提高自己项目的minSdkVersion大于等于三方的即可。

3.use tools:overrideLibrary="com.android.device.geo.device_sdk" to force usage :在AndroidMainifest.xml中加入下面加上:

即可

7.Android解决INSTALL_FAILED_CONFLICTING_PROVIDER错误的方法

参考文章

blog.csdn.net/sinat_29235…

8.A RenderFlex overflowed by 48 pixels on the right

参考文章:

blog.csdn.net/shayubuhuif…

溢出屏幕了,跟着提示

new Expanded( 
    child: new Column( 
        // XXXX 
    ), 
) //基本都是 包裹 Column

9.DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Only valid value is 0:

问题:dio发送post请求一直报错

DioError [DioErrorType.DEFAULT]: RangeError (index): Invalid value: Only valid value is 0:

原因:请求url只写了ip,缺少协议信息 :http://

这里需要注意是否开启了代理 ,需要代理proxy 加上 http:// 或者https://

10.flutter 报错 DioError [DioErrorType.DEFAULT]: Bad state: Insecure HTTP is not allowed by platform

参考下面链接 ,测试没问题

www.cnblogs.com/sea-stream/…

/android/app/src/main/AndroidManifest.xml中,添加

android:networkSecurityConfig="@xml/network_security_config"

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>

<network-security-config>

    <base-config cleartextTrafficPermitted="true" />

</network-security-config>
  1. flutter无法运行 Error retrieving device properties for ro.product.cpu.abi:

真机调试的时候 出现可能就是 需要重新andorid studio,再不行重新启动电脑,如果是模拟器的时候 清除一下模拟器数据,重启andorid studio