M. Hagos
M. Hagos

Reputation: 209

could not get unknown property 'android' for project ':shared_preferences' of type org.gradle.api.project

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

Answers (5)

kisa
kisa

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

Cynthia Konar
Cynthia Konar

Reputation: 304

Upgrading gradle in my current flutter project worked for me:

  1. Open another project with the latest version of flutter
  2. Open android/build.gradle
  3. Check the classpath version of gradle being used. For me it was:

classpath 'com.android.tools.build:gradle:7.2.0'

  1. Update the classpath in your current project to the same.
  2. Open android/gradle/wrapper/gradle-wrapper.properties in the other project
  3. Check the distributionUrl. For me it was:

distributionUrl=https://services.gradle.org/distributions/gradle-7.5-all.zip

  1. Update your current project to use the same one.
  2. Re-run your current app.

Upvotes: 6

Rukamakama
Rukamakama

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.

enter image description here

As reminder you can find the gradle version of your App like following Android >>> build.gradle enter image description here

Upvotes: 8

Amir Parsa
Amir Parsa

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

M. Hagos
M. Hagos

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

Related Questions