flutter - ios 踩坑研究,如何搭建一个稳定的工作环境

3,443 阅读5分钟

IOS上面上次代码运行了,下次不一定可以继续运行

建议大家,每次添加插件后都打个标签,遇到问题看不懂的问题,先把原生代码恢复到上次,还不行就恢复依赖到上次,然后还不行就想想是不是更新了什么环境,把环境还原。

每次恢复的过程中,都可能修改到了别的问题,出现新的问题,这时候清理缓存,再次恢复上个版本代码(因为其他操作又导致了刚刚恢复的内容被修改了)

遇到issues建议修改原生代码的,一律不管他,可以是可以解决问题,但是上次既然没有这个问题,这次肯定有存在的原因,避免进入更复杂的场面

正题,这次我

代码运行后结果如下

搜了下,都是让我更新。

我依然记起上个月,我拿着电脑在楼下创业公司蹭网一早上。

当时,我去楼下小坐,打开电脑开始写flutter,我希望能看到漂亮的单身妹子路过。

然后我输入flutter run,等待运行,然后报错了。

在这个过程中,我没有更新包,没有修改代码 而上次我只是关闭电脑 这次我点开运行而已

我感觉到了窒息

然后根据错误,找到了答案,我不争气的按照别人说的开始更新一堆东西,然后可以了。


这一次,我遇到了错误,但是不不看提示(看了也没找到好的解决方案,依然是让我更新环境)

倔强的我拒绝了,我想知道,到底哪里出了问题,我正常运行,凭什么让我更新环境。

难道我离线就不能开发了么。

于是开始了探索之旅。

上面那个错误,直接看我是找不到好的方案,于是开始修改依赖。

然后每一次修改都会更新,,更新依赖🈶️贼慢,因为我用vscode,vscode里面的dart插件就是这样,然后我修改配置拒绝让它自动更新。

然后发现有了新的错误,我的天。。

之前的错误被刷走了,我丢失了研究的机会。

然后还是一堆问题,于是我新建一个flutter项目, 我想知道到底flutter有没有挂掉。然后发现它正常运行。

flutter create myapp

接着把里面的依赖一个个加过去,比如把IOS的包加过去,竟然一样,然后我就把安卓也加过去,竟然可以了,但是这时候我没有添加依赖,我把依赖又加上去,发现挂掉了。

然后运行一会儿,flutter整个都挂掉了。 我去新建的项目运行也是。

这时候我发现环境出了问题,找到flutter目录,(不是项目目录),里面会有错误信息,也就是.log结尾的问题。看了下错误,发现是git的错误,说git第一次需要提交。

什么鬼。

去你的吧,干脆把git代码初始化,因为肯定有哪里被改了。

对了 导致flutter环境挂掉的是这个命令 flutter doctor

而之所以我要运行这个是因为,运行run的时候,提示找不到设备,我开了模拟器的,这个没有问题,我也查看了下设备确实存在,有截图为证

看有一个可用的ISO设备, 而运行却跟我说不存在,,,我的天。

最后呢,跑到git目录下面执行

git checkout . && git clean -xdf

嗯 可以了

接着问题还没有解决

我又不死心,既然文件都一样,凭什么新建的项目可以运行,可能是哪里又被修改了,虽然我刚刚复制过去不久,于是一次性复制了安卓 iOS lib代码 和依赖 并且执行了flutter clean 这时候果然不报莫名其妙的错误了,

开始正经如下错误。

[!] Automatically assigning platform `ios` with version `8.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`.

Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.
To update the CocoaPods specs, run:
  pod repo update
  
  
Error running pod install
Error launching application on iPhone Xʀ.

这里说的是需要安装ios依赖,需要去ios根目录安装

cd ios
pod install --verbose

每次修改完成ios记得执行下 flutter clean

(pod是ios的包管理器命令,包管理器叫CocoaPods)

完成之后

这时候

    [!] `<PBXGroup UUID=`97C146E51CF9000F007C117D`>` attempted to initialize an
    object with an unknown UUID. `CF3B75C9A7D2FA2A4C99F110` for attribute:
    `children`. This can be the result of a merge and  the unknown UUID is being
    discarded.
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    error:
    /Users/xiexiuyue/Documents/www/flutter/cjyy/ios/Flutter/Debug.xcconfig:1:
    could not find included file 'Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths (in target
    'Runner')
    error:
    /Users/xiexiuyue/Documents/www/flutter/cjyy/ios/Flutter/Debug.xcconfig:1:
    could not find included file 'Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths (in target
    'Runner')
    error:
    /Users/xiexiuyue/Documents/www/flutter/cjyy/ios/Flutter/Debug.xcconfig:1:
    could not find included file 'Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths (in target
    'Runner')
    error:
    /Users/xiexiuyue/Documents/www/flutter/cjyy/ios/Flutter/Debug.xcconfig:1:
    could not find included file 'Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths (in target
    'Runner')
    error:
    /Users/xiexiuyue/Documents/www/flutter/cjyy/ios/Flutter/Debug.xcconfig:1:
    could not find included file 'Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths (in target
    'Runner')
    error:
    /Users/xiexiuyue/Documents/www/flutter/cjyy/ios/Flutter/Debug.xcconfig:1:
    could not find included file 'Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig' in search paths (in target
    'Runner')
    warning: Capabilities for Runner may not function correctly because its
    entitlements use a placeholder team ID. To resolve this, select a
    development team in the build settings editor. (in target 'Runner')
    note: Using new build systemnote: Planning buildnote: Constructing build
    description

Could not build the application for the simulator.
Error launching application on iPhone Xʀ.

安装一些插件会导致IOS原生代码发生变化,这时候如果以为单单是因为改了然后恢复原来的,继续执行,如果发现错误就clean然后继续,会发现错误继续。

没错,flutter runflutter pub get 都会导致IOS原生代码的修改,这时候不管怎么搞,代码都无法执行,这时候就得找到上次得代码了,然后看最近添加的几个包里面,排查是哪个包出现的问题。

--未完,持续更新--