Since gradle android plugins 2.2-alpha4:
Gradle will attempt to download missing SDK packages that a project depends on
Which
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.