我在Android env(模拟器)上使用共享首选项版本2.1.0后遇到了问题。问题是这样陈述的(如果你愿意回答我的问题,非常感谢):
What went wrong:
A problem occurred configuring project ':shared_preferences_android'.
> Could not load compiled classes for build file 'C:\Users\rakhtama\AppData\Local\Pub\Cache\hosted\pub.dev\shared_preferences_android-2.1.0\android\build.gradle' from cache.
> Failed to notify project evaluation listener.
> Could not get unknown property 'android' for project ':shared_preferences_android' of type org.gradle.api.Project.
> Could not get unknown property 'android' for project ':shared_preferences_android' of type org.gradle.api.Project.
这是与错误相关的文件:
C:\Users\rakhtama\AppData\Local\Pub\Cache\hosted\pub.dev\shared_preferences_android-2.1.0\android\build.gradle:
group 'io.flutter.plugins.sharedpreferences'
version '1.0-SNAPSHOT'
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
}
}
rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
apply plugin: 'com.android.library'
android {
compileSdkVersion 33
defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'AndroidGradlePluginVersion', 'InvalidPackage', 'GradleDependency'
baseline file("lint-baseline.xml")
}
dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-inline:5.0.0'
}
testOptions {
unitTests.includeAndroidResources = true
unitTests.returnDefaultValues = true
unitTests.all {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
}
}
{project-folder}\android\gradle\wrapper\gradler-wrapper. properties
{project-folder}\android\build.gradle:
{project-folder}\android\gradle.properties:
pubspec.yaml:
如果你愿意回答我的问题,非常感谢。
我已经尝试运行“flutter clean”&“.\gradlew clean build”,但错误仍然存在。
2条答案
按热度按时间cngwdvgl1#
1.看起来你的Flutter项目中的shared_preferences_android库有问题。这里有一些可能的解决方案:
1.在终端中运行flutter clean来清理你的项目,然后再次尝试构建项目。
1.检查是否已将shared_preferences和shared_preferences_android包添加到项目的pubspec.yaml文件中。如果没有,将它们添加为依赖项,并在终端中运行flutter pub get。
1.检查是否已将shared_preferences和shared_preferences_android包添加到项目的build.gradle文件的dependencies部分。如果尚未添加,请添加它们,然后在终端中运行flutter clean和flutter pub get。
1.如果您仍然面临相同的问题,请尝试删除pub缓存文件夹(C:\Users\rakhtama\AppData\Local\Pub\Cache\hosted\pub.dev)中的shared_preferences_android文件夹,然后再次运行flutter clean和flutter pub get。这将强制Flutter再次下载该软件包。
44u64gxh2#
只要按照下面的步骤,就可以解决了,
1.在终端中运行
flutter clean