天天看点

flutter iOS AttributeError: ‘NoneType’ object has no attribute ‘ConnectRemote’

本次bug起因是:真机是iOS 14.1系统,运行在Xcode 11上编译不了,于是升级到Xcode 12之后,flutter run就报了莫名其妙的错误:AttributeError: ‘NoneType’ object has no attribute ‘ConnectRemote’,AttributeError: 'NoneType' object has no attribute 'modules',AttributeError: 'NoneType' object has no attribute 'process',具体如下:

Launching lib/main.dart on Seaony 的iPhone in debug mode...
 
Automatically signing iOS for device deployment using specified development team in Xcode project: ZSLQ5LJNGF
Running Xcode build...                                                  
                                                   
 └─Compiling, linking and signing...                        12.1s
Xcode build done.                                           25.5s
Traceback (most recent call last):                                      
  File "/tmp/D3B5FF15-60C6-4F10-8BC8-18F8236B8048/fruitstrap_00008030_001E31660A82802E.py", line 25, in connect_command
    process = lldb.target.ConnectRemote(listener, connect_url, None, error)
AttributeError: 'NoneType' object has no attribute 'ConnectRemote'      
Traceback (most recent call last):                                      
  File "/tmp/D3B5FF15-60C6-4F10-8BC8-18F8236B8048/fruitstrap_00008030_001E31660A82802E.py", line 45, in run_command
    lldb.target.modules[0].SetPlatformFileSpec(lldb.SBFileSpec(device_app))
AttributeError: 'NoneType' object has no attribute 'modules'            
Traceback (most recent call last):                                      
  File "/tmp/D3B5FF15-60C6-4F10-8BC8-18F8236B8048/fruitstrap_00008030_001E31660A82802E.py", line 74, in safequit_command
    process = lldb.target.process                                       
AttributeError: 'NoneType' object has no attribute 'process'            
Installing and launching... 
           

百度了许久找不到有用的资料,这时候该尝试Google了,很多大佬都是直接Google,我还是喜欢先百度一下,毕竟骨子里还是习惯中文。。。

Google搜索报错的信息立马有线索,这里贴上线索链接:

1、https://github.com/flutter/flutter/issues/66093

这篇文章出自flutter GitHub上,标题明确,xcode 12运行在flutter 1.17.6上出的错跟我一毛一样,也说了解决方法,升级flutter到1.20.4。也就是flutter版本跟xcode版本不兼容呗。

但不适合我,首先是,我目前接盘的项目不能升级flutter,会出一堆问题,这也是前人留下的坑。

2、https://github.com/flutter/flutter/issues/60072

此篇文章也是出自flutter GitHub官方问题反馈区,有一个点给出了问题所在:

flutter iOS AttributeError: ‘NoneType’ object has no attribute ‘ConnectRemote’

大概意思就是:“我相当确定Flutter确实捆绑了自己的ios部署。ios-deploy可执行文件是一个完全独立的二进制文件(它没有数据文件或库依赖性),因此您应该能够找到它并交换它。”(谷歌翻译...)

也就是根本原因低版本的flutter包含的ios-deploy文件与最新的xcode 12或者说iOS 14不兼容,替换它完事。也给出了ios-deploy的下载地址,可是怎么替换它呢?

3、https://github.com/flutter/flutter/issues/64045

继续查阅相关信息,这篇帖子给出了ios-deploy下载地址和替换步骤(我就直接翻译成中文了):

flutter iOS AttributeError: ‘NoneType’ object has no attribute ‘ConnectRemote’

说的很清楚,下载下来之后要xcode运行,起初我就是下载下来之后没有运行,所以找不到products文件夹下的ios-deploy,运行之后找到,按步骤替换新的即可。

截止,下载新的Xcode 12才能在flutter 1.17.x的环境下跑起来iOS 14,终于解决不升级flutter SDK也能用了,立下此贴,以告后人!

flutter还比较新,坑比较多,碰到问题找起来真费劲,多在flutter GitHub问题去找找,或者Google。各位共勉!