Reputation: 209
i am trying to use shared preference in my app and before I even use it, just adding the dependency gives me this error. anyone with any idea? thanks in advance
Upvotes: 13
Views: 32861
Reputation: 21
I encountered this same issue recently and fixed it by simply deleting the following folders and rebuilding the project.
C:\Users\"username"\AppData\Local\Pub\Cache
and
C:\Users\"username"\.gradle\caches
Upvotes: 2
Reputation: 304
Upgrading gradle in my current flutter project worked for me:
classpath 'com.android.tools.build:gradle:7.2.0'
distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip
Upvotes: 6
Reputation: 1168
In adroid studion Project management section select Project
>>> External Libraries
>>> Flutter Plugins
>>> shared_preferrences_2.x.x
>>> build.gradle
and change the gradle version to match the one of your App.
As reminder you can find the gradle version of your App like following
Android >>> build.gradle
Upvotes: 8
Reputation: 126
I had this problem with aapt2-proto and fix it in this way:
in project-folder/gradle/wrapper/gradle-wrapper.properties
change this:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
to this:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
and then in project-folder/buil.gradle
change this:
classpath 'com.android.tools.build:gradle:3.5.0'
to this:
classpath 'com.android.tools.build:gradle:4.1.1'
and then run this command
flutter clean
build or run your project, good luck.
Upvotes: 9
Reputation: 209
I fixed it by changing the gradle version in the shared preferences build.gradle file to match with the one in the android folder in the flutter app.
Upvotes: 0