423

I am getting this error in jitpack, I've tried everything on the internet. Below is my error

Failed to install the following Android SDK packages as some licences have not been accepted.
     platforms;android-26 Android SDK Platform 26
     build-tools;28.0.3 Android SDK Build-Tools 28.0.3
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.

And when i run ./sdkmanager --licenses

 All SDK package licenses accepted.======] 100% Computing updates...             

Using sudo with the above command gives

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
    ... 5 more

additional error log

File /opt/android-sdk-linux/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Build-Tools 28.0.3 in /opt/android-sdk-linux/licenses
Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
Checking the license for package Android SDK Platform 26 in /opt/android-sdk-linux/licenses
Warning: License for package Android SDK Platform 26 not accepted.

I don't know why it's checking for licenses there when my sdk location is other

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Reenath Reddy Thummala
  • 4,261
  • 2
  • 11
  • 9
  • 1
    There seems to be a slightly mad [solution here](https://stackoverflow.com/a/54283093/608312), it may work though! – Jake Lee Jan 21 '19 at 11:02
  • 8
    I had the same problem. I downloaded the relevant SDKs via Android Studio, and at no point did it ask me about any licences. Another unnecessary problem. – Steve Smith Aug 08 '19 at 08:23
  • 2
    I "accepted" the licenses, but it must have not saved since the android sdk directory was read-only. Chmod 777-ing the sdk directory made things work for me. `sudo chmod -R 0777 /opt/android-sdk` – nathanfranke Jul 09 '21 at 00:17
  • @nathanfranke this is a good point - if the Android SDK directories are not writeable the licence acceptance doesn't stick. You can probably also get around that by running as the user that owns those folders, or is in a group ownership of the folders, depending on how the folders have been installed. – Dan Gravell Sep 02 '21 at 12:25
  • sudo chown User -R /usr/lib/android-sdk – mullerivan Nov 14 '21 at 22:46

32 Answers32

605

You need to accept the licences before building.

According to Android SDK docs you can use the following command depending on the sdkmanager location: Docs on --licenses option seems to be missing though.

yes | sdkmanager --licenses

GNU/Linux Distributions:

yes | ~/Android/Sdk/tools/bin/sdkmanager --licenses

macOS:

export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home
yes | ~/Library/Android/sdk/tools/bin/sdkmanager --licenses

Windows:

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

Flutter:

> flutter config --android-sdk 'path-of-android-sdk'(only for ubuntu user)
> flutter doctor --android-licenses
Felix Too
  • 11,614
  • 5
  • 24
  • 25
  • 137
    I got this error `Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema` – HendraWD Jun 10 '19 at 09:29
  • 17
    @HendraWD If you have installed an extra Java in your computer(Note: Android Studio has it's own Java), You should make sure they have same version. Otherwise It may will occur this error. I solved it just now by setting "Android Studio/jre" path to JAVA_HOME. – Chinese Cat Jul 15 '19 at 07:35
  • 12
    For a Mac without Java installed, I had to `export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home`, `cd ~/Library/Android/sdk/tools/bin`, `./sdkmanager --licenses`. – Graham Perks Oct 31 '19 at 14:38
  • 3
    FWIW: It also seems like only JDK < 11 is supported, and funnily enough, Ubuntu 18.04 comes with `openjdk 11` as the default jdk. After making sure I was using a supported java version, I instead got `Error: Could not create the Java Virtual Machine`, and I found that I had to invoke `sdkmanager` using sudo. – JHH Jan 28 '20 at 19:25
  • I had to run the command with sudo in ubuntu, yes | sudo ~/Android/Sdk/tools/bin/sdkmanager --licenses – mramsath Jun 20 '20 at 14:02
  • 6
    For newbies, %ANDROID_HOME% means the path where sdk is installed – Hanako Oct 05 '20 at 04:49
  • on Windows hit `WIN+R` and execute the commande : `%ANDROID_HOME%/tools/bin/sdkmanager --licenses` – Nouar Nov 23 '20 at 14:14
  • 4
    @HendraWD this answer fixed the problem with the Xml error: https://stackoverflow.com/a/68210820/191463 – Jonathan. Sep 21 '21 at 13:59
  • In Ubuntu 22.04 inside Virtualbox , and latest Android studio 2022.1.1 Patch 1 "Electric Eel", With this specs, this is the path to sdkmanager: *~/Android/Sdk/cmdline-tools/latest/bin* – Jorge Pérez Feb 22 '23 at 21:40
360

In Android Studio go to Tools -> SDK Manager.

Go to SDK Tools tab.

Select the Android SDK Command-line Tools (latest) and download by pressing Apply.

enter image description here

On Windows, you can find the sdkmanager.bat at

C:\Users\[your_user]\AppData\Local\Android\Sdk\cmdline-tools\latest\bin

enter image description here

george mano
  • 5,948
  • 6
  • 33
  • 43
91

in Windows OS go to your sdkmanager path then execute

./sdkmanager.bat --licenses

You can find your sdkmanager in C:\Users\USER\AppData\Local\Android\Sdk\tools\bin

OR

For those people not using android studio on window os. Go to your cmdline-tools\tool\bin and type cmd on the directory box to open the directory in your terminal. Then run sdkmanager --licenses

To find your actual android SDK path follow the red marked area of the below picture

enter image description here

Masum
  • 4,879
  • 2
  • 23
  • 28
  • 1
    After this you can review each license and accept them accordingly through same bash window (Windows CMD throws an error. Use git bash or other instead of windows CMD) – Tharusha Feb 22 '20 at 20:42
  • 8
    I tried this and got a Java classdefnotfound error for some reason for XmlSchema. – John Gorenfeld Apr 21 '21 at 09:22
  • Or copy "cmdline-tools" content to Sdk\cmdline-tools\latest folder and run [sdkmanager.bat --licenses] in Sdk\cmdline-tools\latest\bin adress – MrSalesi Jul 06 '22 at 18:53
56

If you are working with Flutter then this command would definitely work for you.

flutter doctor --android-licenses
RalfFriedl
  • 1,134
  • 3
  • 11
  • 12
51

Problem: SDK license not accepted

enter image description here

Step 1: Open SDK Manager

After opening the SDK manager, open the SDK tools tab as shown below

enter image description here

Step 2: Check the option Show Package Details

It'll list out all the versions of SDK tools

enter image description here

Step 3: Install the required SDK tool version

Check the specific version of SDK tools that is complaining (for me, it was 29.0.3 as shown above in the first screenshot) from the list, accept the agreement in the dialog that opens next and you're done.

Damercy
  • 939
  • 8
  • 10
43

MacOS Catalina

Step 1: Changing Android Studio Preference

  1. Open-up your Android Studio
  2. Press Command+, or go to top-left AppBar Android Studio > Preferences.
  3. From Left Pane, select Appearance > System Settings > Android SDK
  4. Select SDK Tools next to SDK Platforms and under Android SDK Location
  5. Check mark Android SDK Command-line Tools (latest) and Press OK button.
  6. Wait for installation to be finished

Locating Preferences of Android Studio

Android Studio Preferences

Step 2 (For Flutter Users):

  1. Go to Terminal and run the following command

flutter doctor --android-licenses

Step 2 (For Android Users):

  1. Go to the Terminal and run the following command

export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home

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

Zaman
  • 551
  • 4
  • 8
  • Perfect and very useful answer. Out of all the answers and different solutions I have tried, only this one worked well for me. I am using ionic and mac and the above solution was perfect and the detailed steps was very helpful. Thank you. – Neel Dec 30 '20 at 16:11
  • Thank you so much. Steps 1 and 2 for flutter users worked for me. I'm currently using macOS Big Sur 11.6 and new to flutter and android studio setup all together. Again, thank you! – Mary Obiagba Dec 20 '21 at 00:53
38

You can accept the license agreements of the stated SDKs by going to the SDK Manager (Settings > [Search for Android SDK]) then find the packages noted in the error message and find them there. Chances are, you'll find SDKs that are not fully installed and installing them will ask you to accept the license agreement. enter image description here

hamthenormal
  • 856
  • 8
  • 21
  • 2
    Thanks for this, it makes a _lot_ more sense to be able to accept the licenses within AS than to mess about in command line. Worked a charm, should be at the top. – dKen Jul 20 '21 at 13:40
  • @dKen no problem. Thank you for appreciating it. – hamthenormal Jul 22 '21 at 02:58
  • 1
    For me the SDK also needed to be updated, but to get my app to finally compile I also need to install the Android-SDK-Command-Line-Tools. – Thomas S. Dec 02 '21 at 15:50
15

This works for me:

yes | ./sdkmanager "platforms;android-28"

yes | ./sdkmanager "build-tools;28.0.3"

yes | ./sdkmanager --licenses

Angelo Mendes
  • 905
  • 13
  • 24
  • 1
    Worked fine for me (Ubuntu 19.10, IntelliJ 2019.2.4). I just had to install openJDK because I had only the embedded JDK, not accessible from terminal `sudo apt install openjdk-8-jdk` – 56ka Nov 07 '19 at 02:47
14

use android-28 with build-tools at version 28.0.3; or build-tools at version 26.0.3.

or try this: yes | sudo sdkmanager --licenses

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
14

For Android Studio Arctic Fox, it was solved for me by installing the Google Play Licensing Library.

  1. Go to Preferences
  2. Expand Appearance & Behavior
  3. Then expand System Settings
  4. Select Android SDK and go to SDK Tools tab
  5. Install Google Play Licensing Library

enter image description here

artenson.art98
  • 1,543
  • 15
  • 15
11

If you are getting this error while using Flutter then please run the below command on command prompt.

flutter doctor --android-licenses

If you get below error after running the above command

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)

Then please do the below steps

  1. Open android studio
  2. Go to SDK manager
  3. Click on SDK tools tab
  4. Install Android SDK command line tool
  5. Run flutter doctor --android-licenses again
NADIRSHA
  • 145
  • 1
  • 5
10

In Android Studio go to: Tools > SDK Manager > SDK Tools

On the bottom right, check the "Show Package Details" box and download the version of sdk that you need:

Android Studio Sdk Tools

s.dragos
  • 582
  • 2
  • 8
  • 24
8

Tried this on Android Studio and it worked for me:

Tools > SDK Manager (Make sure to check Show Packages below)

SDK Platforms > Show Packages > Android - 28 SDK Platforms > Show Packages > Android - 28

SDK Tools > Show Packages > 28.0.3 SDK Tools > Show Packages > 28.0.3

Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46
Mitzo
  • 81
  • 1
  • 2
6

Appears to be a bug at the momment: https://issuetracker.google.com/issues/123054726

Solution that worked for me:

Create a .travis.yml file in your project directory and copy these lines:

before_script:
- mkdir "$ANDROID_HOME/licenses" || true
- echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license"

Reference: https://github.com/square/RxIdler/pull/18/files

AussieOz
  • 71
  • 1
  • 5
6

in Windows OS go to your sdkmanager path directory in cmd

You can find your sdkmanager in C:\Users\USER\AppData\Local\Android\Sdk\tools\bin

then execute the followwing command:

sdkmanager --licenses

after that it will ask to accept license agreement several times then accept all by just typing y on cmd

Ragini Gupta
  • 147
  • 1
  • 6
3

This works for me in Windows 10:

C:
cd \Users\YOUR_USER\AppData\Local\Android\Sdk\cmdline-tools\latest\bin
sdkmanager.bat --licenses

After, yes to all

3

On Ubuntu it still didn't work using the answers suggested.

This is what worked for me:

cd full-path-to-bin folder, where sdkmanager is located.

yes | ./sdkmanager --licenses --sdk_root="full-path-to-bin"

In the option --help it shows we can pass common args to it, which finally accepted ALL licences:

Usage:
...
sdkmanager --licenses [<common args>]
...
Common Arguments:
    --sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK containing this tool
  • This works. I did not want Android Studio so instead i downloaded the [Android SDK](https://developer.android.com/studio/#command-tools) , switched to the directory bin and ran the above command. It accepted all the licenses after – Ndeto Mar 24 '22 at 06:05
2

On Mac OS 10.15.1, I got the same error even after accepted all the licenses by running sdkmanager --licenses It worked after I updated the ANDROID_HOME path configuration in the ~/.bash_profile to the following

export ANDROID_HOME=/Users/your_username/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export PATH=$PATH:~/Library/Android/sdk/platform-tools

And reload the ~/.bash_profile

source ~/.bash_profile 
s-hunter
  • 24,172
  • 16
  • 88
  • 130
2

I tried many solutions but didn't work for me. The below solution works for me.

locate the sdkmanager file in android SDK.

In my case : ~/Android/Sdk/tools/bin

go to that path : cd ~/Android/Sdk/tools/bin

Accept licenses manually : ./sdkmanager --licenses Enter Yes or y

shubham rasal
  • 91
  • 1
  • 4
2

If you are using flutter go with the following steps

1.open the command prompt

Then the following command

2.C:\Users\niroshan>flutter doctor

And you will see the issues as follows

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.2, on Microsoft Windows [Version 10.0.17763.1339], locale en-US)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    X Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 4.1.0)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[√] VS Code (version 1.50.1)
[!] Connected device
    ! No devices available

! Doctor found issues in 3 categories.

Actually what you have to run is the below command

C:\Users\niroshan>flutter doctor --android-licenses
Niroshan Ratnayake
  • 3,433
  • 3
  • 20
  • 18
2

https://www.youtube.com/watch?v=g789PvvW4qo really helped me. What had done is open SDK Manager and download any new SDK Platform (dont worry it wont affect your desired api level).

Because with downlaoding any SDK Platforms(API level), you should accept licences. That's the trick worked for me.

necip
  • 333
  • 4
  • 11
2

I had the same problem when trying to run an app on my android device in a different project where I was working with some old version of tomcat8 and had to set the JAVA_OPTS variable and value. So I removed this system variable for JAVA_OPTS, which had a Variable value set to -Xms1024m (Remove the JAVA_OPTS system variable, but you can also store it for future use if you need to revert to using your old projects that might need it).

Then run the SDK manager bat file in your sdk path: PS C:\Users[your_pc_username]\AppData\Local\Android\Sdk\tools\bin> .\sdkmanager.bat --licenses

Accept all licenses (Y).

Daniel Ado
  • 514
  • 4
  • 7
2

How I solve this problem (AndroidStudio 4.2)

  • Click in Build tab
  • Select Failed to install the following Android SDK packages ... (warning)
  • Click Install missing SDK package(s)
Linh
  • 57,942
  • 23
  • 262
  • 279
1

To add to the answers, you can also change to the sdkmanager directory and in a sub shell and accept the licenses there

(
    cd /home/user/android-sdk-linux/tools/bin
    yes | ./sdkmanager --licenses
)
the_prole
  • 8,275
  • 16
  • 78
  • 163
1

I just done File -> Invalidate caches and restart Then install missing packages. Worked for me.

1

On Windows:

  1. Add USER Environment variables:

NOTE: Path should be appended

JAVA_HOME           %ProgramFiles%\Android\Android Studio\jre
ANDROID_SDK_ROOT    %LocalAppData%\Android\Sdk
Path                %LocalAppData%\Android\Sdk
  1. Run the below command to accept licenses:

NOTE: Accept all licenses (say y)

%ANDROID_SDK_ROOT%/tools/bin/sdkmanager.bat --licenses
  1. Now run your app:

(like below, or another command that failed for you):

cd \myapp\
react-native run-android
Manohar Reddy Poreddy
  • 25,399
  • 9
  • 157
  • 140
1

in my case I just installed a new version of android studio on a new laptop and cloned the old repository where buildToolsVersion "30.0.2" at application level build.gradle. I just upgraded to 30.0.3 which android studio recommended on its own and the problem went away

Vahag Chakhoyan
  • 873
  • 1
  • 10
  • 21
1

I moved my Sdks and Avds folder as it was using lots of memory in local disk c, but after that I got the above issue.

For me Invalidate Caches/Restart solve the issue

File->Invalidate Caches/Restart

Kunal Kalwar
  • 685
  • 6
  • 20
0

In my case updating buildToolsVersion in app level build.gradle worked perfectly. If you don't know which to use you can create new project and copy buildToolsVersion from that into existing one.

0

A one liner solution with downgrade to java 8:

sudo apt-get install openjdk-8-jdk -y && export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 && flutter doctor --android-licenses
Antonin GAVREL
  • 9,682
  • 8
  • 54
  • 81
0

Just visit to the Build.gradle(Module Appname.app) here, find the "buildToolsVersion" and change the version to "32.0.0"

cigien
  • 57,834
  • 11
  • 73
  • 112
UTTAM
  • 319
  • 3
  • 4
0

On Ubuntu, make sure that the accepted licenses are in the correct location. After accepting them with ./sdkmanager --licenses I had to copy them to the licenses directory directly under android-sdk with:

cp /usr/lib/android-sdk/tools/bin/licenses/* /usr/lib/android-sdk/li censes

IAmCoder
  • 3,179
  • 2
  • 27
  • 49