Since gradle android plugins 2.2-alpha4:
Gradle will attempt to download missing SDK packages that a project depends on
Which
In Windows PowerShell, you can do
for($i=0;$i -lt 30;$i++) { $response += "y`n"}; $response | sdkmanager --licenses
This is much more flexible and requires zero manual intervention. The 30 number is arbitrary, should be enough to cover the number of license acceptances, but can be increased if needed