skip to Main Content

I have a problem after using Shared Preferences version 2.1.0 on Android env (emulator).
The problem is stated like this (thank you very much if you are willing to answer my question) :


What went wrong:
A problem occurred configuring project ':shared_preferences_android'.
> Could not load compiled classes for build file 'C:UsersrakhtamaAppDataLocalPubCachehostedpub.devshared_preferences_android-2.1.0androidbuild.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.

And this is files related to the error :


C:UsersrakhtamaAppDataLocalPubCachehostedpub.devshared_preferences_android-2.1.0androidbuild.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}androidgradlewrappergradler-wrapper.properties
enter image description here


{project-folder}androidbuild.gradle :
enter image description here


{project-folder}androidgradle.properties :
enter image description here


pubspec.yaml :
enter image description here


Thank you very much if you are willing to answer my question.

I have tried to run "flutter clean" & ".gradlew clean build" but the error stil exist.

2

Answers


    1. It seems like there is an issue with the shared_preferences_android library in your Flutter project. Here are some possible solutions:
    2. Clean your project by running flutter clean in the terminal and then try building the project again.
    3. Check if you have added the shared_preferences and shared_preferences_android packages to your project’s pubspec.yaml file. If not, add them as dependencies and run flutter pub get in the terminal.
    4. Check if you have added the shared_preferences and shared_preferences_android packages to your project’s build.gradle file under dependencies section. If not, add them and then run flutter clean and flutter pub get in the terminal.
    5. If you are still facing the same issue, try deleting the shared_preferences_android folder in your pub cache folder (C:UsersrakhtamaAppDataLocalPubCachehostedpub.dev) and then running flutter clean and flutter pub get again. This will force Flutter to download the package again.
    Login or Signup to reply.
  1. Just follow the below step, it will be resolved,

    1. RUN flutter clean in the terminal

    2. Pug get from pubspec.yamal

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search