611

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 ?

15
  • 15
    You can also pop an echo y | in front of that command to auto accept the licence. Useful when running on a headless CI box :)
    – Dori
    Commented Jul 15, 2016 at 11:22
  • 4
    I had to do ~/.android/tools/android update sdk --no-ui --filter build-tools-25.0.0,android-25,extra-android-m2repository because the android tool was localized to my home
    – Jacksonkr
    Commented Mar 13, 2017 at 20:13
  • 8
    sdkmanager --licenses no longer works. I used --upgrade, ignored the errors and this sorted the license problems.
    – jcsubmit
    Commented Nov 15, 2017 at 12:57
  • 7
    I've used this command for CI environment build script with small adjustment. I've added --sdk_root=$ANDROID_SDK_PATH. Problem was that licenses were accepted and not saved to Android SDK root folder. Final command: yes | sdkmanager --licenses --sdk_root=$ANDROID_SDK_PATH (without sudo)
    – adi9090
    Commented Apr 16, 2018 at 12:39
  • 6
    Be sure to have set $ANDROID_SDK_PATH to the actual root path where you've installed the SDK (i.e.: /opt/android-sdk), or just put the path directly (i.e.: yes | sdkmanager --licenses --sdk_root=/opt/android-sdk)
    – gmc
    Commented Nov 7, 2018 at 21:14

65 Answers 65

550

UPDATE 2021 This should be the accepted answer as its easy and upto date


AndroidSDK can finally accept licenses.

Go to Android\sdk\tools\bin

yes | sdkmanager --licenses

EDIT:

as pointed out in the comments by @MoOx, on macOS, you can do

yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager --licenses

as pointed out in the comments by @pho, @mikebridge and @ Noitidart on Windows, you can do

cmd.exe /C"%ANDROID_HOME%\tools\bin\sdkmanager.bat --licenses"

be sure to install java before

26
  • 8
    On Widows I had to go to Run then C:\Users\x1\AppData\Local\Android\sdk\tools\android then it popped open a GUI and then install missing then click "Accept Liscenses" in new dialog that pops.
    – Noitidart
    Commented Dec 25, 2017 at 22:02
  • 20
    This is not working for linux. There is no sdkmanager file under the tools/bin dir or somewhere else. Can you please help? Commented Jan 23, 2018 at 13:46
  • 46
    On macOS, you can do yes | sudo ~/Library/Android/sdk/tools/bin/sdkmanager --licenses
    – MoOx
    Commented Jan 30, 2018 at 10:56
  • 6
    How can I accept licenses automatically from gradle wrapper? Commented Mar 7, 2018 at 16:00
  • 9
    upvote to @Noitidart for the path, but it didn't work, I had to run C:\Users\x1\AppData\Local\Android\sdk\tools\bin\sdkmanager --licenses from the command prompt and hit "y" + Enter to the prompts
    – coder
    Commented Oct 1, 2018 at 3:18
299

I was getting this error:

License for package Android SDK Build-Tools 30.0.2 not accepted.

So, I went to Tools -> SDK Manager -> SDK Tools. Then I installed Google Play Licensing Library. It solved the problem.

enter image description here

9
  • 2
    I'm afraid I'm going to have to disagree with @AminPinjari and Cedric, this didn't make a darn bit of difference for me.
    – Michael
    Commented Jan 31, 2021 at 18:07
  • 1
    I don't understand why this is needed with a fresh install of AS but I'm happy that this answer exists! I just installed this and then did a gradle sync and all was great. Commented Aug 3, 2021 at 12:06
  • 1
    I found and used this solution for my issues while I was using a Windows PC. I shifted to Mac, found the same problem and the same solution fixed my issue yet again. This is the best answer as of 2021. Commented Aug 15, 2021 at 10:29
  • 1
    And what is the equivalent on the command line? Commented Feb 12, 2022 at 17:39
  • 1
    can someone point out how can we do it using command line (debian)?
    – aquaman
    Commented Sep 21, 2022 at 11:44
186

I have encountered this with the alpha5 preview.

Jake Wharton pointed out to me that you can currently use

mkdir -p "$ANDROID_SDK/licenses"
echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"
echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK/licenses/android-sdk-preview-license"

to recreate the current $ANDROID_HOME/license folder on you machine. This would have the same result as the process outlined in the link of the error msg (http://tools.android.com/tech-docs/new-build-system/license).

The hashes are sha1s of the licence text, which I imagine will be periodically updated, so this code will only work for so long :)

And install it manually, but it is the gradle's new feature purpose to do it.

I was surprised at first that this didnt work out of the box, even when I had accepted the licenses for the named components via the android tool, but it was pointed out to me its the SDK manager inside AS that creates the /licenses folder.

I guess that official tools would not want to skip this step for legal reasons.

Rereading the release notes it states

SDK auto-download: Gradle will attempt to download missing SDK packages that a project depends on.

Which does not mean it will work if you have not installed the android tools yet and have already accepted the latest license(s).

EDIT: Saying that, it still does not work on my test gubuntu box until I link the SDK up to AS. CI works fine though - not sure what the difference is...

12
  • There is a small glitch in sdkDownload feature regarding some of the components, e.g., support-v4. It will update the components but gradle won't see update until next invocation. One workaround to exec gradle twice, once to throw away: gradle dependencies || true -- code.google.com/p/android/issues/detail?id=212309 Commented Oct 17, 2016 at 6:08
  • 6
    you can use mkdir -p instead of || true.
    – oldergod
    Commented Oct 17, 2016 at 6:33
  • It works thank you for this glitch, good to know. To check if your SDK path is defined as expected : echo $ANDROID_SDK
    – tryp
    Commented Feb 21, 2017 at 9:53
  • In my environment ANDROID_SDK is not defined, but it works with ANDROID_HOME Commented Apr 18, 2017 at 11:38
  • 5
    @stack_ved: I've just added another echo: echo -e "\nd56f5187479451eabf01fb78af6dfcb131a6481e" >> "${ANDROID_HOME}/licenses/android-sdk-license". But I think your problem hides somewhere else.
    – Paul
    Commented Oct 16, 2017 at 16:58
147

For the newest Android Studio (2.3) the best way to update/accept all licenses is to run:

cd $ANDROID_HOME
tools/bin/sdkmanager --licenses

you might still need to copy the licence files to other locations based on your setup.

8
  • This looks like the best way to go and it works on all platforms too, just run tools/bin/sdkmanager --licenses
    – jnv
    Commented Apr 24, 2017 at 22:35
  • If you got old sdk manager --licenses wont work. It is necessary to copy tools folder to another location then use --sdk_root= and point it to your sdk folder, then you would be able to update tools to newer version. Commented Oct 9, 2017 at 10:54
  • can we pipe yes into this command somehow for automated build systems? You won't always have interactive console access to these machines, so pressing y on keyboard physically won't work. Commented Oct 13, 2017 at 14:41
  • 1
    Can anyone please guide me how to implement this solution? Got to add this line in build.sh?
    – stack_ved
    Commented Oct 16, 2017 at 16:45
  • 1
    it worked for me but i had to do cd $ANDROID_HOME before executing this command
    – Inus Saha
    Commented Dec 6, 2017 at 10:46
61

For the new sdkmanager utility:

yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;24.0.3"

There's a bit of a delay between yesses, so the command could hang with the license showing for a while, but it doesn't require human intervention.

5
  • In my install debian9 I only have a sdkmanager.jar: android-sdk-linux/tools/lib/sdkmanager.jar and # java -jar /android-sdk-linux/tools/lib/sdkmanager.jar Error: The tools directory property is not set, please make sure you are executing android Commented Oct 19, 2017 at 17:41
  • 1
    This is based on the assumption that you downloaded the SDK tools as an archive from Google and unpacked them into $ANDROID_HOME
    – A. Rager
    Commented Nov 9, 2017 at 20:09
  • This seems the most up-to-date answer. It seems --licenses does not exist anymore. Note: to see list of possible versions that can be provided: $ANDROID_HOME/tools/bin/sdkmanager --list
    – Marinos An
    Commented Jun 5, 2018 at 12:36
  • 2
    Thanks for the hint. I ended up using yes | android-sdk-linux/tools/bin/sdkmanager --licenses || true in my CI.
    – iSWORD
    Commented Jul 17, 2018 at 19:19
  • es | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;28.0.3" -> changing the version worked for me . Thanks ! Commented Feb 19, 2019 at 3:44
46

If you are using Jenkins, you can use the following bash script as first step in the build process:

(while sleep 3; do echo "y"; done) | $ANDROID_HOME/tools/android update sdk -u

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.

4
  • I add your line of code before "cordova platform add android" in my jenkins build which is running on Ubuntu but still getting following error : BUILD FAILED in 7s Error: /var/lib/jenkins/workspace/qa_global_php/platforms/android/gradlew: Command failed with exit code 1 Error output: FAILURE: Build failed with an exception. * What went wrong: A problem occurred configuring root project 'android'. > You have not accepted the license agreements of the following SDK components: Commented Dec 12, 2017 at 6:39
  • [Android SDK Build-Tools 26.0.2]. 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. Commented Dec 12, 2017 at 6:39
  • "The sleep is to avoid the broken readline in the installation program" <- What does that mean?
    – Khoa Vo
    Commented Jan 4, 2022 at 8:26
  • That android tool is deprecated Commented Feb 3, 2022 at 22:46
36

this solved my error

echo yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;25.0.2"
1
  • 2
    To save a few characters, yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;25.0.2" does the same thing. Commented May 27, 2018 at 16:39
36

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 be able to 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"

4
  • 2
    this one solved the issue in my case too (build tools 26.0.x), with Jenkins in Docker. Thanks!
    – Giordano
    Commented Nov 3, 2017 at 12:11
  • 2
    Unfortunately this does not include the "automatically" part of the question.
    – m0skit0
    Commented Feb 12, 2019 at 10:07
  • @m0skit0 thanks for your comment! I've updated the question to match with last version feature to automatically accept all licenses without human intervention. Commented Feb 14, 2019 at 0:14
  • @Maruf install the Android SDK and add it to the path :·) Commented Jul 12, 2021 at 11:37
32

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

 
To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.14.1/userguide/gradle_daemon.html.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 24.0.2].

...
BUILD FAILED

NOTE: 2017-04-16

The android tool has now been deprecated in favor of the new sdkmanager. Please see Joe Lawson's answer and subsequent posts from March (2017) and onward.

Then adjust you command as follows:

android update sdk --no-ui --filter build-tools-24.0.2,android-24,extra-android-m2repository
Refresh Sources:
  Fetching https://dl.google.com/android/repository/addons_list-2.xml
  Validate XML
  Parse XML
  Fetched Add-ons List successfully
  Refresh Sources
  Fetching URL: https://dl.google.com/android/repository/repository-11.xml
  Validate XML: https://dl.google.com/android/repository/repository-11.xml
  Parse XML:    https://dl.google.com/android/repository/repository-11.xml
...
Error: Ignoring unknown package filter 'build-tools-24.0.2'
-------------------------------
License id: android-sdk-license-xxxxxxxx
Used by: 
 - SDK Platform Android 7.0, API 24, revision 2
  - Android Support Repository, revision 39
-------------------------------

...

November 20, 2015
Do you accept the license 'android-sdk-license-xxxxxxxx' [y/n]: y

Installing Archives:
  Preparing to install archives
  Downloading SDK Platform Android 7.0, API 24, revision 2
  Installing SDK Platform Android 7.0, API 24, revision 2
    Installed SDK Platform Android 7.0, API 24, revision 296%)
  Downloading Android Support Repository, revision 39
  Installing Android Support Repository, revision 39
    Installed Android Support Repository, revision 3999%)
  Done. 2 packages installed.

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!)

1
  • 1
    android update sdk --no-ui --filter build-tools-24.0.2,android-24,extra-android-m2repository running this via command prompt with admin right fixed the error. I was unable to install phonegap plugin manager
    – Ravimallya
    Commented Jan 7, 2017 at 9:15
24

The android tool is deprecated and you should use the sdkmanager 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 command

echo -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"

works 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.

echo -n -e "\n8933bad161af4178b1185d1a37fbf41ea5269c55" > "$ANDROID_SDK/licenses/android-sdk-license"

If that isn't working you can try using the base64 encoding instead.

So to discover my license:

$> rm ${ANDROID_HOME}/
$> unzip tools_r25.2.3-linux.zip -d ${ANDROID_HOME}
$> ${ANDROID_HOME}/tools/bin/sdkmanager "system-images;android-23;default;x86_64"

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 use base64.

$> base64 ${ANDROID_HOME}/licenses/android-sdk-license
Cjg5MzNiYWQxNjFhZjQxNzhiMTE4NWQxYTM3ZmJmNDFlYTUyNjljNTU=

Then you can use base64 -d recreate the file exactly.

$> echo Cjg5MzNiYWQxNjFhZjQxNzhiMTE4NWQxYTM3ZmJmNDFlYTUyNjljNTU= | base64 -d > ${ANDROID_HOME}/licenses/android-sdk-license

You can verify if the file written is what is expected by running a sha1sum on it.

$> sha1sum ${ANDROID_HOME}/licenses/android-sdk-license
da6b80c9c47b41c0bf7032938e7137a58a3dc249
19

if you run yes | sdkmanager --licenses, then we print content of $ANDROID_HOME/licenses/android-sdk-license,

we will get this

# cat $ANDROID_HOME/licenses/android-sdk-license

8933bad161af4178b1185d1a37fbf41ea5269c55

d56f5187479451eabf01fb78af6dfcb131a6481e

For GitLab CI, to accept Android SDK Build-Tools 26.0.2 licenses, you need to run this

before_script:
  - mkdir -p $ANDROID_HOME/licenses
  - echo "8933bad161af4178b1185d1a37fbf41ea5269c55" > $ANDROID_HOME/licenses/android-sdk-license
  - echo "d56f5187479451eabf01fb78af6dfcb131a6481e" >> $ANDROID_HOME/licenses/android-sdk-license
9
  • You're second echo is going to the same $ANDROID_HOME/licenses/android-sdk-license is this intended? ie. appending
    – Ryan R
    Commented Oct 11, 2017 at 19:05
  • 1
    @RyanR, yes, the second echo is appending, Android SDK Build-Tools 26.02 added a new license sha1 string
    – jk2K
    Commented Oct 12, 2017 at 3:41
  • I'm using bitbucket pipelines, but the concept seems to be the same as with GitLab CI. Your answer helped me understand the whole process better. Thanks!
    – Ridcully
    Commented Oct 12, 2017 at 12:12
  • @Ridcully I'm also using Bitbucket Pipelines and found myself here when we upgraded to Build-Tools 26.0.2 and our build broke. My end solution was to simply do yes | sdkmanager --licenses. No echos needed and this is future proof.
    – Ryan R
    Commented Oct 12, 2017 at 23:11
  • @Ryan You mean I can just add 'yes | sdkmanager --licenses' to the pipeline.yml? That would be great!
    – Ridcully
    Commented Oct 13, 2017 at 6:31
17

Note that for anyone coming to this question currently, build-tools-24.0.2 is (I think) now considered obsolete, so you'll get:

 Error: Ignoring unknown package filter 'build-tools-24.0.2'

when running the various commands that have been suggested to install them.

The solution is to add --all:

android update sdk --no-ui --all --filter "build-tools-24.0.2"

Also if you're on 32bit linux, everything after build tools 23.0.1 is 64bit only, so will not run. 32bit users are stuck on 23.0.1, the only way to get a later build tools is to switch to 64bit.

2
  • 1
    Yeah, build-tools was just bumped to 25.0.1.
    – not2qubit
    Commented Nov 23, 2016 at 17:55
  • 1
    Your solution was the only thing I could find to work on a headless ubuntu 16 machine for build-tools-25 and gradle 4
    – spartygw
    Commented Feb 27, 2018 at 23:00
15

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

2
  • Still quite relevant after several months. Thank you. You saved my day :) Commented Jan 21, 2019 at 9:28
  • This was helpful for me, also using GitLab
    – sebasira
    Commented Jan 30, 2019 at 14:56
15

You can also just execute:

$ANDROID_HOME/tools/bin/sdkmanager --licenses

And in Windows, execute:

%ANDROID_HOME%/tools/bin/sdkmanager --licenses
14

Ok FOR ANYONE HAVING THIS ISSUE AS OF 2018. The above answers did NOT work for me at all. What DID work was opening Android SDK - clicking the DOWNLOAD button on the tool bar and selecting the appropriate packages. After they finish downloading, it will let you accept the license agreement.

enter image description here

12

In Android Studio for Windows, the solution is as follows:

Go to File -> Settings -> Appearance & Behaviour -> System Settings -> Android SDK -> SDK Tools -> check Google Play Licensing Library -> Click Apply, and then Ok

After the installation, build your application. It will work.

1
  • It worked! Welcome to the community :-) Commented Nov 11, 2021 at 17:09
11

For an error message about SDK api number 25:

android update sdk --no-ui --all --filter build-tools-25.0.1,android-25,extra-android-m2repository

0
9

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.

9

Note: This is only for Mac users

I had same issue but none of the answers posted helped since there was no tools folder present in Library/Android/sdk. (I'm using Android 3.6.3 on Mac OS 10.14.4)

error screenshot

Below steps helped me to overcome licensing problem error:

  1. Open Android Studio
  2. Press cmd + shift + A. This opens Actions pop-up window.
  3. Search for SDK Manager and hit enter to open.
  4. This opens pop-up for Android SDK. Select some other version of Android apart from already installed one. (In my case Android 10.0 was already installed so I selected Android 9.0)
  5. Then select Apply button. This will install corresponding SDK.

Solution

  1. Now run your app it should work without any exception.

success screenshot

0
7

I solved this problem by creating a public git repo with the accepted license files. Then I use wget to fetch these licenses on any machine I need into a [sdk-dir]/licenses directory before running ./gradlew to build my project.

2
  • Unfortunately, your solution doesn't tell me how to solve the problem. Can you share how you obtained the "license files"? Commented Nov 13, 2021 at 23:22
  • @FrederickNord Licenses are obtained from your $ANDROID_HOME/sdk/licenses on your computer. Commented Nov 15, 2021 at 14:58
7

I went to Tools -> SDK Manager -> SDK Tools. Then I installed Google Play Licensing Library. It solved the problem.

2
  • 1
    For MacOS, this works Commented Dec 17, 2021 at 13:43
  • And for Monterey the accepted answer appears not to work, so this one is required!
    – Markers
    Commented Jan 20, 2022 at 12:25
6

cd $ANDROID_HOME/tools/bin yes | ./sdkmanager --update

or

yes | $ANDROID_HOME/tools/bin/sdkmanager --update

1
  • "Automatically"
    – m0skit0
    Commented Feb 12, 2019 at 10:14
6

for windows, open cmd and enter into bin directory by running command:

cd C:\Users\username\AppData\Local\Android\sdk\tools\android\Sdk\tools\bin

then run sdkmanager --licenses command, it asks to accept licenses.

2
  • 1
    Thanks this is what I did Commented Jun 9, 2019 at 15:31
  • I get Error: Unknown argument --licenses Commented Nov 8, 2019 at 9:31
5

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

1
  • Great answer, this worked for me still in 2023. Running above command allowed me to accept all licenses, then I was able to use sdkmanager to install all the packages I needed without issue.
    – Chris
    Commented May 26, 2023 at 12:58
5

I finally found a solution on Windows, to have a real silent and automatic install:

On Windows, the following syntax doesn't work:

echo y | sdkmanager --licenses

It seems the "y" aren't correctly sent to the java program called in the batch.

The workaround is to create a file file-y.txt with several "y", one by line, and to use

call sdkmanager --licenses < file-y.txt

This will create the needed files in the licenses directory. The problem is probably related to the use of BufferedReader in Java

4

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

enter image description here

1
  • None of the CMD commands worked for me, only this solution. Thanks Commented Nov 8, 2019 at 10:13
4

Here is my Docker setup.
You can follow from a plain Linux environment.

Note that yes | and --licenses --sdk_root=${ANDROID_HOME} clauses.
It seems sdkmanager --update reverts agreements, so yes | is appeared twice.

FROM openjdk:8
# Install dev-essential(gnumake)
RUN apt update
RUN apt install -y build-essential
# Set ENV
ENV SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" \
    ANDROID_HOME="/usr/local/android-sdk" \
    ANDROID_VERSION=28 \
    ANDROID_BUILD_TOOLS_VERSION=28.0.3 \
    GRADLE_VERSION=4.10.3 \
    NDK_VERSION=r16b
# Download Android SDK
RUN mkdir "$ANDROID_HOME" .android \
    && cd "$ANDROID_HOME" \
    && curl -o sdk.zip $SDK_URL \
    && unzip sdk.zip \
    && rm sdk.zip \
    && yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses --sdk_root=${ANDROID_HOME}
# Install Android Build Tool and Libraries
RUN $ANDROID_HOME/tools/bin/sdkmanager --update
RUN yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
    "platforms;android-${ANDROID_VERSION}" \
    "platform-tools" --sdk_root=${ANDROID_HOME}
# Install Gradle
RUN wget https://services.gradle.org/distributions/gradle-${GRADLE_VERSION}-all.zip
RUN mkdir /opt/gradle
RUN unzip gradle-${GRADLE_VERSION}-all.zip -d /opt/gradle
ENV PATH=${PATH}:/opt/gradle/gradle-${GRADLE_VERSION}/bin
# Install NDK
RUN wget https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux-x86_64.zip
RUN mkdir /opt/ndk-bundle
RUN unzip android-ndk-${NDK_VERSION}-linux-x86_64.zip -d /opt/ndk-bundle
ENV PATH=${PATH}:/opt/ndk-bundle

RUN mkdir /application
WORKDIR /application
1
  • "It seems sdkmanager --update reverts agreements, so yes | is appeared twice." Wow, you're right. This is very frustrating but good find.
    – cephus
    Commented Jan 23, 2019 at 4:14
4

Download the SDK manager from this link. Then unzip and use the following command in terminal.

!tools/bin/sdkmanager --sdk_root=/usr/lib/android-sdk --licenses <<< $'y\ny\ny\ny\ny\ny\ny\n'
1
  • That <<< $'y\ny\ny\ny\ny\ny\ny\n' part did the trick on my side. Thanks dude!
    – asozcan
    Commented Feb 20, 2023 at 16:46
3

Copy the entire licenses/ directory and paste it into the Android SDK home directory on the machine where you wish to build your projects.

https://developer.android.com/studio/intro/update.html#download-with-gradle

this resolved the issue for me

3

I had the same error while using Cordova.

The problem was due to the fact that I installed Android Sdk through Android Studio and through apt with apt install android-sdk adb. And Cordova was calling the files installed through apt instead of the files in my home directory.

It worked once I changed the path to SDK in bash:

# Change path
export ANDROID_HOME="$HOME/Android/Sdk/"
echo "Android home = $ANDROID_HOME"
# Accept licenses
eval "${ANDROID_HOME}/tools/bin/sdkmanager --licenses"
# Run Cordova
cordova build android

Then I removed the system files that weren't used anymore: apt remove android-sdk adb.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.