Could not create task ‘:shared_preferences_android:generateDebugUnitTestConfig‘
flutter项目使用shared_preferences库的时候,打开flutter项目中的android项目运行,会出现如下错误信息:
A build operation failed.
Could not create task ':shared_preferences_android:generateDebugUnitTestConfig'.
Could not create task ':shared_preferences_android:generateDebugUnitTestConfig'.
this and base files have different roots: D:\flutterproject\demo\build\shared_preferences_android and C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.flutter-io.cn\shared_preferences_android-2.3.3\android.
解决方案:
方法一:把提示的C盘路径下的shared_preferences_android删除,如果C盘有flutter项目,需要把flutter项目build里的shared_preferences_android也删除。
方法二:直接将D盘里报错的flutter项目移到桌面。
方法三:暂时屏蔽pubspec.yaml 文件中shared_preferences: ^2.3.1的引入,flutter clean一下项目,此时再去运行android项目就不报错啦;记得回到flutter项目的时候打开依赖项