flutter启动时出现Could not resolve al
2020-06-30 本文已影响0人
维他命丶
当启动flutter项目时,由于某些第三方库的关系,运行时出现错误如下:
Could not resolve all task dependencies for configuration ‘:XXX:debugCompileClasspath’.
Could not resolve project :XXX_macos.
Required by:
project :XXX
Unable to find a matching configuration of project :XXX_macos:
- None of the consumable configurations have attributes.
Could not resolve project :XXX_web.
Required by:
project :XXX
Unable to find a matching configuration of project :XXX_web:
- None of the consumable configurations have attributes.
XXX 是代表某一个第三方库,我遇到过两个,一个是video_player 一个是 shared_preferences库,使用最新版的时候出现这个问题。找了好久的原因,终于在某个帖子找到了一些启示。
首先,这类型错误导致的原因是找不到该库相关依赖的包。这是gradle找不到,不是flutter找不到,所以这个问题的出现是在Android运行时出现的。至于为什么找不到呢?gradle找的是Android的依赖,它当然找不到web和mac的其他相关依赖了。所以解决这个问题的方法,最简单快捷的就是不需要web和mac的依赖,因为做的是手机的APP,而不是网站或者mac的软件。
解决方法:
找到你的flutter的目录,然后找到.pub-cache/hosted/pub.flutter-io.cn的目录,把目录里面所有xxx_web和xxx_macos的文件夹删除掉,然后直接运行你的flutter项目即可。
当然,这只是一个暂时的治标不治本的方案。实际方案估计要等到官方给我们解决了这个问题才可以。