If you use tools/bin/sdkmanager --licenses
you still need to have a human interaction. I have the problem using my gitlab CI. This is my solution:
wget --quiet --output-document=tools.zip https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip
unzip -qq tools.zip
echo y | tools/bin/sdkmanager "platforms;android-25"
echo y | tools/bin/sdkmanager "platform-tools"
echo y | tools/bin/sdkmanager "build-tools;25.0.2"
echo y | tools/bin/sdkmanager "extras;android;m2repository"
echo y | tools/bin/sdkmanager "extras;google;m2repository"
echo y
will say yes if there is any question, but you need to make one line per installe package