Since gradle android plugins 2.2-alpha4:
Gradle will attempt to download missing SDK packages that a project depends on
Which is amazingly cool and was know to be a JakeWharton project.
But, to download the SDK library you need to: accept the license agreements or gradle tells you:
You have not accepted the license agreements of the following SDK components: [Android SDK Build-Tools 24, Android SDK Platform 24]. Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager. Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
And this is a problem because I would love to install all sdk dependencies while doing a gradle build
.
I am looking for a solution to automatically accept all licenses. Maybe a gradle script ? Do you have any ideas ?
Thanks!
[EDIT]
A solution was to execute:
android update sdk --no-ui --filter build-tools-24.0.0,android-24,extra-android-m2repository
And install it manually, but it is the gradle's new feature purpose to do it.
[EDIT 2]
A better solution is to use the sdkmananger:
yes | sudo sdkmanager --licenses
cd $ANDROID_HOME/tools/bin ./sdkmanager --update
The
android
tool is deprecated and you should use thesdkmanager
instead.sdkmanager
also writes the licenses file when you first accept it. The license changes depending on which SDK you are using so even though the commandworks on some systems. It won't work on all. Some SDK installs expect to license file to end without a newline in the file so try adding a
-n
to the echo command.If that isn't working you can try using the base64 encoding instead.
So to discover my license:
It'll prompt you to accept the license. After accepting it'll copy it to
${ANDROID_HOME}/licenses/android-sdk-license
. To ensure you always get exactly what is written usebase64
.Then you can use
base64 -d
recreate the file exactly.You can verify if the file written is what is expected by running a sha1sum on it.
I tried all the above command on windows 10 machine but the solution was to use the SDKMANAGER to check and accept licenses buy installing missing versions
Unfortunately the way as OP originally solved it does not always work. If you find from the error message what is your builds current build-tools version. It could be that it is a higher version of build-tools that is missing. In that case you need to manually start SDK Manager and add the build-tools and accept license.
Per OP instructions, it look as follows.
$ ./gradlew build
Then adjust you command as follows:
Running this again, still do not make Gradle happy. So manual acceptance is the only solution until someone come up with something better. (Please do!)
I navigate to:
and I typed in terminal:
With root permission. And it works for me now.
if you run
yes | sdkmanager --licenses
, then we print content of$ANDROID_HOME/licenses/android-sdk-license
,we will get this
For GitLab CI, to accept Android SDK Build-Tools 26.0.2 licenses, you need to run this