Flutter 颤振:无法确定任务';的依赖关系:共享首选项:compiledBugaidl';

Flutter 颤振:无法确定任务';的依赖关系:共享首选项:compiledBugaidl';,flutter,dart,Flutter,Dart,我在Flatter中创建了一个新的应用程序,当我运行它时,它就可以工作了,但是当我添加共享的首选项包时,我在运行它时遇到了这个错误 FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':shared_preferences:compileDebugAidl'. > Could not resolve all task depend

我在Flatter中创建了一个新的应用程序,当我运行它时,它就可以工作了,但是当我添加共享的首选项包时,我在运行它时遇到了这个错误

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':shared_preferences:compileDebugAidl'.
> Could not resolve all task dependencies for configuration ':shared_preferences:debugCompileClasspath'.
   > Could not resolve project :shared_preferences_macos.
     Required by:
         project :shared_preferences
      > Unable to find a matching configuration of project :shared_preferences_macos:
          - None of the consumable configurations have attributes.
   > Could not resolve project :shared_preferences_web.
     Required by:
         project :shared_preferences
      > Unable to find a matching configuration of project :shared_preferences_web:
          - None of the consumable configurations have attributes.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 866ms
Gradle task assembleDebug failed with exit code 1
这是我的出版物

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: ^0.5.3+1

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
这有什么问题,我如何解决?请帮帮我。。。谢谢

这个问题存在
使用如下修复版本作为解决方法,删除
^

共享首选项:
0.5.3+1

我测试没有错误

完整测试代码

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
        child: RaisedButton(
          onPressed: _incrementCounter,
          child: Text('Increment Counter'),
        ),
      ),
    ),
  ));
}

_incrementCounter() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  await prefs.setInt('counter', counter);
}

这是一个更普遍的问题,会导致多个颤振相关性的问题。在Flatter人员解决根本问题之前,在
pubspec.yml
中回溯问题模块的版本号,直到问题得到解决。似乎添加了MacOS支持的模块都失败了

例如,
url\u启动器:5.3.0
可以工作


注意:不要忘记删除
^
,这样它可以获得比您指定的更新版本。

我可以通过运行以下命令来解决此问题:

$ flutter pub cache repair
颤振:(移除^) 共享首选项:^0.5.3+1->共享首选项:0.5.3+1


android stuio:file->invalidate Cahces/restart

我从GitHub找到了这个解决方案,请尝试一下,并告诉我它是否有效! 在PowerShell中执行以下命令:

setx PUB_HOSTED_URL "https://pub.flutter-io.cn"
setx FLUTTER_STORAGE_BASE_URL "https://storage.flutter-io.cn"
之后,在您的颤振终端:

flutter pub cache repair

你真是个天才!删除“^”对我来说很有效,这就是问题所在!!