Since gradle android plugins 2.2-alpha4:
Gradle will attempt to download missing SDK packages that a project depends on
Which
We found same issue building the project on Jenkins. With buildToolsVersion '25.0.2', we must accept licenses before building. In our case, we needed to run:
yes | sdkmanager --update that accepts licenses for the sdkmanager itself, and then
yes | sdkmanager --licenses that accepts new licenses not previously accepted
Remember: run these commans with the same user that jenkins does. In our Debian, the Jenkins user is just jenkins. In other words: doing it as root will create the accepted licenses as root, so Jenkins will not read them.
By the way, we found sdkmanager at /var/lib/jenkins/tools/android-sdk/tools/bin. If yours is not there, find it with find / -name "sdkmanager"