android – Flutter run error : You have not accepted the license agreements-ThrowExceptions

Exception or error:

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.

How to solve:

try these:

  1. Open your terminal
  2. type flutter doctor --android-licenses
  3. press y to accept every license.

###

First make sure Android SDK is installed on your device.
Also see if 2 Android SDK’s are not Installed!

Then just simply type on Terminal or CMD flutter doctor --android-licenses
Then press y until it acquires all permissions.

###

For me , flutter doctor --android-licenses didn’t work for some reason.

The only cmd that worked & solved it all was this:

(your android_sdk folder exact path)\tools\bin\sdkmanager --licenses

###

I think is a little late to answer this question, but I think this can be useful for those who are starting in Flutter like me.

In my case (at my machine), I’ve executed the steps below:

  1. Execute command prompt as administrator;
  2. Run the command flutter doctor –android-licenses and accept all licenses;
  3. Run the command flutter doctor -v to check if the issue was solved;
  4. To make sure that is everything is ok, execute the command prompt as a regular user (your user) and execute flutter doctor -v again

enter image description here

I hope this helps.

###

Open the command prompt then run flutter doctor --android-licenses and accept all the licenses given.

###

If you are in windows open command prompt as admin and run the following command.

flutter doctor --android-licenses

Then enter y for all (y/n) to accept agreement.

###

C:\Users\bansal>flutter doctor --android-licenses

A newer version of the Android SDK is required. To update, run:

D:\android SDK\tools\bin\sdkmanager --update

Leave a Reply

Your email address will not be published. Required fields are marked *