在 Android 环境上使用共享首选项版本 2.1.0 后出现 Flutter gradle 错误

问题描述 投票:0回答:2

我在 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:\用户 akhtama\AppData\Local\Pub\Cache\hosted\pub.dev\shared_preferences_android-2.1.0 android uild.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
            }
        }
    }
}

{项目文件夹} android\gradle\wrapper\gradler-wrapper.properties


{项目文件夹} android uild.gradle :


{项目文件夹} android\gradle.properties :


pubspec.yaml:


如果您愿意回答我的问题,非常感谢

我尝试运行“flutter clean”和“.\gradlew clean build”,但错误仍然存在。

android flutter dart gradle
2个回答
0
投票
  1. 您的 Flutter 项目中的 shared_preferences_android 库似乎存在问题。以下是一些可能的解决方案:
  2. 通过在终端中运行 flutter clean 来清理你的项目,然后再次尝试构建项目。
  3. 检查您是否已将 shared_preferences 和 shared_preferences_android 包添加到项目的 pubspec.yaml 文件中。如果没有,请将它们添加为依赖项并在终端中运行 flutter pub get。
  4. 检查您是否已将 shared_preferences 和 shared_preferences_android 包添加到依赖项部分下项目的 build.gradle 文件中。如果没有,请添加它们,然后在终端中运行 flutter clean 和 flutter pub get。
  5. 如果您仍然面临同样的问题,请尝试删除 pub 缓存文件夹 (C:\Users) 中的 shared_preferences_android 文件夹 akhtama\AppData\Local\Pub\Cache\hosted\pub.dev) 然后再次运行 flutter clean 和 flutter pub get。这将强制 Flutter 重新下载包。

0
投票

只需按照以下步骤即可解决,

  1. 在终端

    中运行
    flutter clean

  2. Pug 从 pubspec.yamal 获取

© www.soinside.com 2019 - 2024. All rights reserved.