我在flutter中创建了一个新应用,当我运行它时它可以正常工作,但是当我添加shared_preferences包时,我在运行它时遇到了这个错误
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
这是我的pubspec.yaml
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 :(得分:2)
这是一个更普遍的问题,导致具有多个抖动依赖性问题。在Flutter员工解决基本问题之前,请在pubspec.yml
中回溯问题模块的版本号,直到问题解决为止。添加MacOS支持的模块似乎全部失败。
例如,url_launcher: 5.3.0
有效。
注意:不要忘记删除^
,使其获得比您指定的版本更高的版本。
答案 1 :(得分:1)
此问题存在
使用如下修复版本作为解决方法,删除^
shared_preferences: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);
}
答案 2 :(得分:0)
Flutter :(删除^) shared_preferences:^ 0.5.3 + 1-> shared_preferences:0.5.3 + 1
android stuio:文件->使Cahces /重启无效
答案 3 :(得分:0)
我从 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