when I add Shared_Preferences dependency my project doesn't run
当我添加Shared_Preferences依赖项时,项目不会运行
Version : last version 2.2.0
版本:最新版本2.2.0
This is the error message:
以下是错误消息:
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring project ':shared_preferences_android'. Could not resolve all files for configuration ':shared_preferences_android:classpath'. Could not find gradle-7.2.2.jar (com.android.tools.build:gradle:7.2.2). Failed to notify project evaluation listener. Could not get unknown property 'android' for project ':shared_preferences_android' of
I added WidgetsFlutterBinding.ensureInitialized()
in the main function. When I remove the dependency my problem did get solved, but I need this dependency for save token as string
我在Main函数中添加了WidgetsFlutterBinding.ensureInitialized()。当我删除依赖项时,我的问题就解决了,但是我需要这个依赖项来将令牌保存为字符串
When I remove the dependency my problem did get solved.
当我移除依赖时,我的问题就解决了。
更多回答
Sometimes some packages can conflict with other packages and show errors. I fixed myself by exchanging/considering other package versions. How about your compileSdkVersion?
有时,某些包可能会与其他包冲突并显示错误。我通过交换/考虑其他包版本来修复自己。你的编译器SdkVersion怎么样?
The problem is stated in the error message output: "Could not find gradle-7.2.2.jar" and that problem occurred configuring project ':shared_preferences_android' which means the issue is not with flutter nor with WidgetsFlutterBinding.ensureInitialized(); line. What is your gradle config, can you share the build.gradle file?
错误消息输出中指出了问题:“找不到Gradle-7.2.2.jar”,并且配置项目‘:Shared_Preferences_Android’时出现问题,这意味着问题既不是颤动问题,也不是WidgetsFlutterBinding.ensureInitialized();行的问题。你的Gradle配置是什么,你能分享build.gradle文件吗?
优秀答案推荐
You have to make sure your gradle version is updated
您必须确保您的Gradle版本已更新
location => android/gradle/wrapper/gradle-wrapper.properties
位置=>android/gradle/wrapper/gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
location => android/build.gradle
位置=>安卓/build.gradle
dependencies { classpath 'com.android.tools.build:gradle:7.4.2' }
after that, you can add your dependencies from the terminal
在此之后,您可以从终端添加依赖项
flutter clean
flutter pub add shared_preferences
flutter pub get
Check your pubspec.yaml
file to ensure that you have added the shared_preferences dependency correctly. It should look something like this:
检查pubspec.yaml文件,确保正确添加了Shared_Preferences依赖项。它应该看起来像这样:
dependencies:
flutter:
sdk: flutter
shared_preferences: ^2.2.0
Run the command flutter pub get
in your project directory to fetch the dependencies.
在您的项目目录中运行fltter pub get命令以获取依赖项。
更多回答
It's right I should update Gradle
是的,我应该更新Gradle
我是一名优秀的程序员,十分优秀!