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
If you are using Jenkins, you can use the following bash script as first step in the build process:
This will of course install ALL available updates, but it will save you some time if you can spare the disk space. The sleep is to avoid the broken readline in the installation program, since "yes" does not work properly in this case.
EDIT: You also need to add the "Install Android project prerequisites" plugin in the build step to get the correct $ANDROID_HOME if you are using the built in SDK manager.
For those having issues with the command line SDK, the reason it won't find the licenses you have accepted is because they have have been written to a different location than
$ANDROID_HOME/licenses
which is where they need to be.I found the easiest solution was to accept the licenses like this:
$ANDROID_HOME/bin/sdkmanager --licenses --sdk_root=$ANDROID_HOME
Note: This assumes you've set
ANDROID_HOME
to point to wherever your sdk is installed.There are 2 approach that I can found to this problem.
Update sdk tools with command window by accepting licence agreement as follows, just change the version according to your need.
android update sdk --no-ui --filter build-tools-25.0.2,android-25,extra-android-m2repository
Second approach is copying licence folders to Android root directory. Goto your development machine open Android Studio. Find your sdk location from Project Structure menu. (C:\Users\UserName\AppData\Local\Android\sdk). Under that directory there must be a licence folder. Copy that folder with the content. Paste that folder in your Jenkins server machine (or where you face with this problem) under android sdk root folder. (C:\Users\UserName.jenkins\tools\android-sdk)
For the newest Android Studio (2.3) the best way to update/accept all licenses is to run:
you might still need to copy the licence files to other locations based on your setup.
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:./sdkmanager --update
that requests us to accept a license for the sdkmanager, and then./sdkmanager --licenses
that requests us to accept new licenses not previously acceptedRemember: run these commans with the same user that
jenkins
does. In my Debian, the Jenkins user is justjenkins
. In other words: doing it asroot
will create the accepted licenses asroot
, 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 withfind / -name "sdkmanager"
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:echo y
will say yes if there is any question, but you need to make one line per installe package