Automatically accept all SDK licences

I have encountered this with the alpha5 preview.

Jake Wharton pointed out to me that you can currently use

mkdir -p "$ANDROID_SDK/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK/licenses/android-sdk-preview-license"

to recreate the current $ANDROID_HOME/license folder on you machine. This would have the same result as the process outlined in the link of the error msg (http://tools.android.com/tech-docs/new-build-system/license).

The hashes are sha1s of the licence text, which I imagine will be periodically updated, so this code will only work for so long :)

And install it manually, but it is the gradle's new feature purpose to do it.

I was surprised at first that this didnt work out of the box, even when I had accepted the licenses for the named components via the android tool, but it was pointed out to me its the SDK manager inside AS that creates the /licenses folder.

I guess that official tools would not want to skip this step for legal reasons.

Rereading the release notes it states

SDK auto-download: Gradle will attempt to download missing SDK packages that a project depends on.

Which does not mean it will work if you have not installed the android tools yet and have already accepted the latest license(s).

EDIT: Saying that, it still does not work on my test gubuntu box until I link the SDK up to AS. CI works fine though - not sure what the difference is...


I was getting this error:

License for package Android SDK Build-Tools 30.0.2 not accepted.

So, I went to Tools -> SDK Manager -> SDK Tools. Then I installed Google Play Licensing Library. It solved the problem.

enter image description here


For the newest Android Studio (2.3) the best way to update/accept all licenses is to run:

cd $ANDROID_HOME
tools/bin/sdkmanager --licenses

you might still need to copy the licence files to other locations based on your setup.


UPDATE 2021 This should be the accepted answer as its easy and upto date


AndroidSDK can finally accept licenses.

Go to Android\sdk\tools\bin

yes | sdkmanager --licenses

EDIT:

as pointed out in the comments by @MoOx, on macOS, you can do

yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager --licenses

as pointed out in the comments by @pho, @mikebridge and @ Noitidart on Windows, you can do

cmd.exe /C"%ANDROID_HOME%\tools\bin\sdkmanager.bat --licenses"

be sure to install java before