how to solve this : you have not accepted the license agreements on flutter?

Viewed 84

3

I'm developing android and ios app with Google flutter. when I add a new dependency like shared_preferences to pubspec.yaml and then execute flutter run in terminal, I got this error:

    What went wrong: A problem occurred configuring project ':shared_preferences'.
    You have not accepted the license agreements of the following SDK components: [Android SDK Platform 27].

I know why it happens! because the latest Android SDK platform on my system is 26 . it trys to download sdk 27 and then fails. no problem! I go to library cached folder which located here :

C:\Users...\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\shared_preferences-0.3.1\android

and edit build.gradle file and change compileSdkVersion 27 to compileSdkVersion 26. it works. so far I have to do this for all new dependencies, Is there any way such as defining a global build.gradle file for all dependencies? so no need to edit each buil.gradles individually.

2 Answers
  • Execute command prompt as administrator.

  • Run the command flutter doctor --android-licenses and accept all licenses.

  • Run the command flutter doctor -v to check if the issue was solved.

  • To make sure that is everything is ok, execute the command prompt as a regular user (your user) and execute flutter doctor -v again.

I tried running flutter -v doctor --android-licenses but it looks like --android-licenses doesn't use the usual ways to launch apps.

In this case I solved it by following this command

Rename C:\Users\%username%\AppData\Local\Android\Sdk\tools folder to tool

Navigate to cd C:\Users\%username%\AppData\Local\Android\Sdk\tool\bin in cmd

And run sdkmanager --update --verbose, will create a new folder tools

Run flutter doctor --android-licenses

Then Accept the android licenses by clicking y

to check flutter doctor if the issue was solved:
Related