106

I downloaded and installed:

  • JDK (jdk-9.0.1_osx-x64_bin.dmg) from Oracle here
  • Android SDK (sdk-tools-darwin-3859397.zip) from Google here.

After configuring the PATH variable, I tried running sdkmanager, which replaced the android command for managing SDK components. However, it failed as shown here:

$ sdkmanager --list
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.SdkManagerCli.main(SdkManagerCli.java:117)
    at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:93)
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:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 5 more

Here is the Java version:

$ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

Does anyone know how to fix it without going back to Java 8?

Related Questions

  • Failed to install android-sdk
    • This post asked a similar question. However, the post is closed and the only answer suggests going back to Java 8.
jww
  • 83,594
  • 69
  • 338
  • 732
  • 1
    Just wondering: what is the purpose of doing this? – GhostCat Nov 07 '17 at 05:14
  • 2
    Trying new features in Java 9, but at the same time developing Android apps, and just want one JDK in the system. – Siu Ching Pong -Asuka Kenji- Nov 07 '17 at 05:16
  • The linked answer is not Android SDK specific. It did not point out which script to edit, and where to edit. Please note that not everybody knows shell script, and it helps to solve the problem quickly even for people who know. Do you want to read though a script not written by you to solve a simple configuration problem, while a working solution is out there already tested by someone? – Siu Ching Pong -Asuka Kenji- Nov 07 '17 at 05:23
  • 3
    On that note, I've voted to reopen https://stackoverflow.com/questions/46402772/failed-to-install-android-sdk even as the comments pointed out. – Naman Nov 07 '17 at 05:39
  • Please don't delete this until https://stackoverflow.com/q/46402772/142239 is re-opened, and I copy my answer there. I don't have a backup of my StackOverflow posts. Thanks! – Siu Ching Pong -Asuka Kenji- Nov 07 '17 at 05:41
  • I was with java latest installed, downgrade for java8 in variables env and work fine – Diego Venâncio May 08 '19 at 15:52
  • none of the solutions worked for me. had to go back to java 8 – Karl May 27 '19 at 21:26

28 Answers28

160

With the help of this answer, I successfully solved the problem.

We are going to apply a fix in sdkmanager. It is a shell script. It is located at $android_sdk/tools/bin, where $android_sdk is where you unzipped the Android SDK.

  1. Open sdkmanager in your favorite editor.
  2. Locate the line which sets the DEFAULT_JVM_OPTSvariable. In my copy, it is at line 31:

    DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME"'
    
  3. Append the following options to the variable: -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee. Please pay attention to the quotes. In my copy, the line becomes:

    DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
    
  4. Save the file and quit the editor.
  5. Run the command again.

Here is the result:

$ sdkmanager --list
Installed packages:
  Path    | Version | Description              | Location
  ------- | ------- | -------                  | ------- 
  tools   | 26.0.1  | Android SDK Tools 26.0.1 | tools/  

Available Packages:
  Path                              | Version      | Description                      
  -------                           | -------      | -------                          
  add-ons;addon-g..._apis-google-15 | 3            | Google APIs                      
  add-ons;addon-g..._apis-google-16 | 4            | Google APIs                      
  add-ons;addon-g..._apis-google-17 | 4            | Google APIs                      
  add-ons;addon-g..._apis-google-18 | 4            | Google APIs                      
  add-ons;addon-g..._apis-google-19 | 20           | Google APIs                      
  add-ons;addon-g..._apis-google-21 | 1            | Google APIs                      
  add-ons;addon-g..._apis-google-22 | 1            | Google APIs                      
  add-ons;addon-g..._apis-google-23 | 1            | Google APIs                      
  add-ons;addon-g..._apis-google-24 | 1            | Google APIs
...

Hola! It works!

-- Edit: 2017-11-07 --

Please note that you may need to apply the fix above again after running sdkmanager --update, since the sdkmanager shell script may be overridden if the tools package is updated.

Related Answers

  • 1
    As noted in the JDK 9 Migration Guide `--add-modules java.se.ee` should be a considered a temporary workaround. The proposal to drop the java.xml.bind module from Java SE and the JDK is in draft form here: https://bugs.openjdk.java.net/browse/JDK-8189188 – Alan Bateman Nov 07 '17 at 08:01
  • Yes, I am aware of that. As the software in concern is the Android SDK, which is developed by Google, I am not responsible or able to do what you suggested. Please send a bug report to Google. Thanks! – Siu Ching Pong -Asuka Kenji- Nov 07 '17 at 08:18
  • 11
    Why not simply export the `JAVA_OPTS` environment variable, `export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'`, instead of patching the SDK source files? – Rafa Feb 07 '18 at 23:33
  • Thanks for your suggestion! That's a good idea! By applying this, there is no need for the user to patch the script again after an upgrade. However, the setting (usually made in shell startup scripts) affects not just sdkmanager, but also other applications as well. And this may not be what the user wants to do. – Siu Ching Pong -Asuka Kenji- Feb 08 '18 at 04:14
  • 7
    FWIW, I downloaded and installed both the JDK and Android SDK Tools today on Windows 10, and had to set the line to be `set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0.." -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee` to get the `com.android.sdklib.tool.SdkManagerCli` class to run correctly – RJ Cuthbertson Feb 20 '18 at 19:06
  • 1
    Sir, did you know that you've just saved someone's life? I could have stroke or something. I did what you said, you've just solved a problem for me, three excruciating, heart wrenching days of trying to get it to work!!!!!!! THANKS A LOT – Mahmoud Feb 21 '18 at 19:39
  • @Mahmoud I'm glad to hear that! Please keep on your good work to write us some fantastic Android apps! – Siu Ching Pong -Asuka Kenji- Mar 02 '18 at 08:36
  • Hi All, Now I got a new problem. XMlSchema error is resolved but now ......Any solution please.* What went wrong: A problem occurred configuring project ':app'. > Failed to notify project evaluation listener. > Could not initialize class com.android.sdklib.repository.AndroidSdkHandler – Dipendra Sharma Mar 20 '18 at 15:47
  • What a burning shame to have releases that are so unfinished and untested. It just feels like some developers dont realize there are many companies that need good job with Android and **problems like this cost thousands of dollars**. – Olivier Pons Apr 22 '18 at 19:31
  • 1
    Though I settled on this solution (easier for me to keep track of), an [alternative "solution" is here](https://stackoverflow.com/a/49630166/5411817). A long term fix would be wonderful. – SherylHohman May 11 '18 at 04:44
  • I agree with @Rafa, setting the `JAVA_OPTS` is easiest. Note that on Windows you need to put it without double quotes: `set JAVA_OPTS=--add-modules java.se.ee` – Amfasis Jul 12 '18 at 09:00
  • I have no tools folder – Ambroise Rabier Oct 17 '18 at 19:21
  • 2
    when having java 11 in the system, the solution that @SherylHohman proposed must be combined with this one, java 11 must be "hidden" from the list to make this work – Alejandro Moya Oct 28 '18 at 15:12
  • 5
    This `-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee` or `--add-modules java.xml.bind do not work with Java 11 on Mac OS. How can I fix it without installing another version of Java? – Manish Oct 29 '18 at 17:10
  • No way to get sdkmanager (at least of version 26.1.1) to run with Java 11 IMO. You need to downgrade or have a separate installation of Java 8..10 configured in "sdkmanager" source with "JAVA_HOME" override – Slava Medvediev Feb 07 '19 at 06:00
  • I still get another error: ```Error: Could not find or load main class '-Dcom.android.sdklib.toolsdir=D:\Android_SDK-26.0.1\tools\bin\\.. Caused by: java.lang.ClassNotFoundException: '-Dcom/android/sdklib/toolsdir=D:\Android_SDK-26/0/1\tools\bin\\//``` – aderchox Jan 17 '20 at 09:55
  • if you are using java 11 or later Try changing this like in sdkmanager.bat "%JAVA_EXE%" %DEFAULT_JVM_OPTS% --add-modules java.xml.bind %JAVA_OPTS% %SDKMANAGER_OPTS% -classpath "%CLASSPATH%" com.android.sdklib.tool.sdkmanager.SdkManagerCli %CMD_LINE_ARGS% – amilamad Oct 06 '20 at 18:06
  • 1
    In ubuntu 18.04 with Java --version 11, this does not work and instead throws the error ``` Error occurred during initialization of boot layer java.lang.module.FindException: Module java.se.ee not found ``` after rerunning the command – Ike Mawira Dec 21 '20 at 08:38
  • Hola == Voila?? – Damn Vegetables Jan 14 '21 at 13:12
37

You can set sdkmanager options with SDKMANAGER_OPTS.

Example:

export SDKMANAGER_OPTS="--add-modules java.se.ee"
sdkmanager --list
bempa
  • 460
  • 4
  • 8
30

The accepted answer is outdated as of February 2019. Here's an answer that will work until sdkmanager migrates to a newer version of Java. But by then, you won't have this problem anymore.

OpenJDK 10 was superseeded by OpenJDK 11, which doesn't implement java.se.ee at all. This means that the hack of adding --add-modules java.se.ee doesn't do anything anymore. It also means that OpenJDK 10 will be automatically removed from your system and replaced with OpenJDK 11 the next time you update, if your updates are configured properly.

Modify sdkmanager to use Java 8 by setting JAVA_HOME inside sdkmanager to a Java 8 installation. It's, by default, at ~/Android/Sdk/tools/bin/sdkmanager.

# Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options $
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions'
@rem Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
set JAVA_HOME="C:\ProgramData\scoop\apps\android-studio\current\jre"
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."

This way, you can keep using a sane and maintained version of Java on your system while simultaneously using sdkmanager.

# Java
export JAVA_HOME=/usr/lib/jvm/default-java

And now I've got some pipelines to repair.

NatoBoram
  • 1,933
  • 2
  • 18
  • 42
  • This answer helped me, as I temporary set JAVA_HOME top point to Java installation from Android Studio: C:\Program Files\Android\Android Studio\jre – clzola Oct 28 '19 at 09:49
  • 3
    `set JAVA_HOME="...\android-studio\current\jre"` helps me on Windows 10 while all other answers didn't – NearHuscarl Jan 15 '20 at 13:08
  • 1
    `set JAVA_HOME="C:\Program Files\Android\Android Studio\jre"` worked fro me on Windows 10. Find out your Android Studio Path. I have set Java 11 on my original JAVA_HOME – notes-jj May 16 '20 at 08:26
  • This won’t work: Java 8 no longer exists in Debian stable (1½ years old) and newer. – mirabilos Sep 30 '20 at 21:57
  • @NatoBoram I use IntelliJ IDEA without the bundled binary JRE. I use the distribution’s JRE because that’s the one with security support, and our machine policy requires us to keep our software secure. – mirabilos Jan 27 '21 at 00:18
  • In 2021, this answer was the one that worked perfectly. – Tanner Feb 14 '21 at 18:05
24

When having java 11 in the system, the solutions provided are not valid.

This -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee or--add-modules java.xml.bind do not work with Java 11 on Mac OS.

For that reason you have to downgrade java version to version 8 from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

List Java versions installed

/usr/libexec/java_home -V

Java 11

export JAVA_HOME=$(/usr/libexec/java_home -v 11)

Java 1.8

export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)

Then go to

cd ~/Library/Android/sdk/tools/bin

and

./sdkmanager --licenses
thodwris
  • 948
  • 12
  • 26
14

Update 2019-10:

As stated in the issue tracker, Google has been working on a new SDK tools release that runs on current JVMs (9+)!

You can download and use the new Android SDK Command-line Tools inside Android Studio or by manually downloading them from the Google servers:

For the latest versions check the URLs inside the repository.xml.

If you manually unpack the command line tools, take care of placing them in a subfolder inside your $ANDROID_HOME (e.g. $ANDROID_HOME/cmdline-tools/...).

Update 2021-03:

The latest stable command-line tools are also available at Googles Downloads-Website

G00fY
  • 2,584
  • 18
  • 23
  • 1
    Command line tools 2.1 (latest) also fail like this, with Java 11. – mirabilos Sep 30 '20 at 21:55
  • thanks, the command line tools works! – Panda World Mar 05 '21 at 02:32
  • @mirabilos there has to be an other issue with your setup. Android Studio Arctic Fox (current Canary) is shipped with JDK11 embedded. It runs fine. And we use Java 11 on our CI machines and never had any issues. – G00fY Mar 05 '21 at 08:59
13

For Windows, if nothing works then try this:

  • Open sdkmanager.bat with Notepad.

  • Locate the following line:

    %JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS%

  • Add --add-modules java.xml.bind

The modified line should look like this:

%JAVA_EXE%" %DEFAULT_JVM_OPTS% --add-modules java.xml.bind %JAVA_OPTS% %SDKMANAGER_OPTS%

skomisa
  • 12,583
  • 7
  • 47
  • 75
Sagar Khatri
  • 405
  • 3
  • 11
11

As we read in the previous comments this error is occurring because the current SDK version is incompatible with the newest Java versions: 9 and 10.

So, to solve it, you can downgrade your java version to Java 8, or as a workaround, you can export the following option on your terminal:

Linux:

export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

Windows:

set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'

If this does not work try to exports the java.xml.bind instead.

Linux:

export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind'

Windows:

set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind'

This will solve this error for the sdkmanager

And to make it saved permanently you can export the JAVA_OPTS in your profile file on Linux (.zshrc, .bashrc and etc.) or add it as an environment variable permanently on Windows.


ps. This doesn't work for Java 11/11+, which doesn't have Java EE modules. For this option is a good idea, downgrade your Java version or wait for a Flutter update.

Ref: JDK 11: End of the road for Java EE modules

valdeci
  • 8,287
  • 4
  • 39
  • 57
  • 14
    When I try this, im getting another error: Error occurred during initialization of boot layer java.lang.module.FindException: Module java.se.ee' not found – Sherin Binu Sep 20 '18 at 05:51
  • @SherinBinu which Java version are you using? – valdeci Sep 20 '18 at 11:45
  • 2
    try to use `--add-modules java.xml.bind` instead of `--add-modules java.se.ee` – valdeci Sep 20 '18 at 12:21
  • The `--add-modules` approach will no longer in Java 11+ I have found this working answer on another post https://stackoverflow.com/questions/53076422/getting-android-sdkmanager-to-run-with-java-11 – lbenedetto Dec 21 '20 at 19:07
  • @lbenedetto, yeah, we can read this at the end of the answer – valdeci Dec 23 '20 at 16:55
  • Yes, but their provided work around of downgrading Java is bad. I linked a post that explains how to download and install the required missing components. – lbenedetto Dec 24 '20 at 18:33
9

As some people have mentioned before, this very well could be a simpler problem having to do with one java installation taking precedence over the other.

In my case it was java 8 being overshadowed by a default newer java.

I installed java 8:

sudo apt-get install openjdk-8-jdk

Then I updated the installed java to be the new default:

sudo update-alternatives --config java

Whereby I selected java 8's id number.

After doing these (pretty simple) steps, I could just run sdkmanager without error.

Hope this helps someone!

Steve Trotta
  • 116
  • 1
  • 2
7

The Android Tools are still incompatible with JDK 9 or 10. You need to install JDK 8 or, if you need multiple Java versions make sure that the system-wide Java home points to a JDK 8.

More details here: How to configure Unity 2017.4 to target Android and avoid build failures on OSX?

German
  • 9,885
  • 4
  • 37
  • 53
5

I had a tough time figuring out this solution just adding the working sdkmanager.bat

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem  sdkmanager startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..

@rem Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."


@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\lib\sdklib-25.3.1.jar;%APP_HOME%\lib\layoutlib-api-25.3.1.jar;%APP_HOME%\lib\dvlib-25.3.1.jar;%APP_HOME%\lib\repository-25.3.1.jar;%APP_HOME%\lib\gson-2.2.4.jar;%APP_HOME%\lib\commons-compress-1.8.1.jar;%APP_HOME%\lib\httpclient-4.1.1.jar;%APP_HOME%\lib\httpmime-4.1.jar;%APP_HOME%\lib\common-25.3.1.jar;%APP_HOME%\lib\kxml2-2.3.0.jar;%APP_HOME%\lib\annotations-25.3.1.jar;%APP_HOME%\lib\annotations-12.0.jar;%APP_HOME%\lib\jimfs-1.1.jar;%APP_HOME%\lib\httpcore-4.1.jar;%APP_HOME%\lib\commons-logging-1.1.1.jar;%APP_HOME%\lib\commons-codec-1.4.jar;%APP_HOME%\lib\guava-18.0.jar

@rem Execute sdkmanager
"%JAVA_EXE%" %DEFAULT_JVM_OPTS%  -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee  %JAVA_OPTS% %SDKMANAGER_OPTS%  -classpath "%CLASSPATH%" com.android.sdklib.tool.SdkManagerCli %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable SDKMANAGER_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if  not "" == "%SDKMANAGER_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
victorjpe
  • 129
  • 1
  • 8
  • I'm afraid it's not viable option since this will stop working when new version of SDK comes out since this code snippet contains hard-coded versions: `set CLASSPATH=%APP_HOME%\lib\sdklib-25.3.1.jar` – izogfif May 02 '18 at 10:40
4

I was able to solve the issue by using an edited sdkmanager.bat file by forcing to use the Java embedded inside the Android Studio Itself, which i presume uses the OpenJDK 8. Here is the edited sdkmanager I Used :

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem  sdkmanager startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..

@rem Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."

@rem find Java from Android Studio
@rem Find java.exe
if defined ANDROID_STUDIO_JAVA_HOME goto findJavaFromAndroidStudioJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

goto findJavaNormally

:findJavaFromAndroidStudioJavaHome
set JAVA_HOME=%ANDROID_STUDIO_JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

goto findJavaNormally




@rem java from java home
@rem Find java.exe
:findJavaNormally
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init

goto javaError

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init

goto javaDirectoryError



:javaError
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:javaDirectoryError
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail


:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\lib\dvlib-26.0.0-dev.jar;%APP_HOME%\lib\jimfs-1.1.jar;%APP_HOME%\lib\jsr305-1.3.9.jar;%APP_HOME%\lib\repository-26.0.0-dev.jar;%APP_HOME%\lib\j2objc-annotations-1.1.jar;%APP_HOME%\lib\layoutlib-api-26.0.0-dev.jar;%APP_HOME%\lib\gson-2.3.jar;%APP_HOME%\lib\httpcore-4.2.5.jar;%APP_HOME%\lib\commons-logging-1.1.1.jar;%APP_HOME%\lib\commons-compress-1.12.jar;%APP_HOME%\lib\annotations-26.0.0-dev.jar;%APP_HOME%\lib\error_prone_annotations-2.0.18.jar;%APP_HOME%\lib\animal-sniffer-annotations-1.14.jar;%APP_HOME%\lib\httpclient-4.2.6.jar;%APP_HOME%\lib\commons-codec-1.6.jar;%APP_HOME%\lib\common-26.0.0-dev.jar;%APP_HOME%\lib\kxml2-2.3.0.jar;%APP_HOME%\lib\httpmime-4.1.jar;%APP_HOME%\lib\annotations-12.0.jar;%APP_HOME%\lib\sdklib-26.0.0-dev.jar;%APP_HOME%\lib\guava-22.0.jar

@rem Execute sdkmanager
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS%  -classpath "%CLASSPATH%" com.android.sdklib.tool.sdkmanager.SdkManagerCli %CMD_LINE_ARGS%

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable SDKMANAGER_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if  not "" == "%SDKMANAGER_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega

Here i used an environmental variable ANDROID_STUDIO_JAVA_HOME which actually points to the JRE embedded in the android studio eg: ../android_studio/jre

This also has a fallback to JAVA_HOME if ANDROID_STUDIO_JAVA_HOME is not set.

Jemsheer K D
  • 161
  • 7
4

This is what I did in Ubuntu 18.04 (Any Linux will do):

$ sudo apt-get install openjdk-8-jdk

$ sudo update-alternatives --config java
There are 2 choices for the alternative javac (providing /usr/bin/javac).

  Selection    Path                                          Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/javac   1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/javac   1111      manual mode
* 2            /usr/lib/jvm/java-8-openjdk-amd64/bin/javac    1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 2

$ export JAVA_HOME=$(/usr/lib/jvm/java-1.8.0-openjdk-amd64)
Vahid
  • 4,285
  • 3
  • 27
  • 42
3

Short addition to the above for openJDK 11 with android sdk tools before upgrading to the latest version.

The above solutions didn't work for me

set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."

To get this working I have installed the jaxb-ri (reference implementation) from the maven repo.

The information was given https://github.com/javaee/jaxb-v2 and links to the https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-ri/2.3.2/jaxb-ri-2.3.2.zip
This download includes a standalone runtime implementation in the mod-Folder.

I copied the mod-Folder to $android_sdk\tools\lib\ and added the following to classpath variable:

;%APP_HOME%\lib\mod\jakarta.xml.bind-api.jar;%APP_HOME%\lib\mod\jakarta.activation-api.jar;%APP_HOME%\lib\mod\jaxb-runtime.jar;%APP_HOME%\lib\mod\istack-commons-runtime.jar;

So finally it looks like:

set CLASSPATH=%APP_HOME%\lib\dvlib-26.0.0-dev.jar;%APP_HOME%\lib\jimfs-1.1.jar;%APP_HOME%\lib\jsr305-1.3.9.jar;%APP_HOME%\lib\repository-26.0.0-dev.jar;%APP_HOME%\lib\j2objc-annotations-1.1.jar;%APP_HOME%\lib\layoutlib-api-26.0.0-dev.jar;%APP_HOME%\lib\gson-2.3.jar;%APP_HOME%\lib\httpcore-4.2.5.jar;%APP_HOME%\lib\commons-logging-1.1.1.jar;%APP_HOME%\lib\commons-compress-1.12.jar;%APP_HOME%\lib\annotations-26.0.0-dev.jar;%APP_HOME%\lib\error_prone_annotations-2.0.18.jar;%APP_HOME%\lib\animal-sniffer-annotations-1.14.jar;%APP_HOME%\lib\httpclient-4.2.6.jar;%APP_HOME%\lib\commons-codec-1.6.jar;%APP_HOME%\lib\common-26.0.0-dev.jar;%APP_HOME%\lib\kxml2-2.3.0.jar;%APP_HOME%\lib\httpmime-4.1.jar;%APP_HOME%\lib\annotations-12.0.jar;%APP_HOME%\lib\sdklib-26.0.0-dev.jar;%APP_HOME%\lib\guava-22.0.jar;%APP_HOME%\lib\mod\jakarta.xml.bind-api.jar;%APP_HOME%\lib\mod\jakarta.activation-api.jar;%APP_HOME%\lib\mod\jaxb-runtime.jar;%APP_HOME%\lib\mod\istack-commons-runtime.jar;

Maybe I missed a lib due to some minor errors showing up. But sdkmanager.bat --update or --list is running now.

2

This is the answer to make this work for Java 11 and above since the entire JAXB APIs were removed.

Download Jakarta XML Binding, specifically this zip file. You need only the 3 files within mod folder i.e. jakarta.activation.jar, jakarta.xml.bind-api.jar and jakarta.xml.bind-api.jar and you can toss the rest off.

Move these files to APP_HOME/lib folder. I created a sub folder jaxb inside for this. So, on my macOS system this was: $HOME/Library/Android/sdk/tools/lib/jaxb

Now open sdkmanager using your favorite text editor and under CLASSPATH= add the following at th beginning:

$APP_HOME/lib/jaxb/jakarta.activation.jar:$APP_HOME/lib/jaxb/jakarta.xml.bind-api.jar:$APP_HOME/lib/jaxb/jaxb-impl.jar

So it ended up looking like:

CLASSPATH=$APP_HOME/lib/jaxb/jakarta.activation.jar:$APP_HOME/lib/jaxb/jakarta.xml.bind-api.jar:$APP_HOME/lib/jaxb/jaxb-impl.jar:$APP_HOME/lib/dvlib-26.0.0-dev.jar:$APP_HOME/lib/jimfs-1.1.jar:$APP_HOME/lib/jsr305-1.3.9.jar:$APP_HOME/lib/repository-26.0.0-dev.jar:$APP_HOME/lib/j2objc-annotations-1.1.jar:$APP_HOME/lib/layoutlib-api-26.0.0-dev.jar:$APP_HOME/lib/gson-2.3.jar:$APP_HOME/lib/httpcore-4.2.5.jar:$APP_HOME/lib/commons-logging-1.1.1.jar:$APP_HOME/lib/commons-compress-1.12.jar:$APP_HOME/lib/annotations-26.0.0-dev.jar:$APP_HOME/lib/error_prone_annotations-2.0.18.jar:$APP_HOME/lib/animal-sniffer-annotations-1.14.jar:$APP_HOME/lib/httpclient-4.2.6.jar:$APP_HOME/lib/commons-codec-1.6.jar:$APP_HOME/lib/common-26.0.0-dev.jar:$APP_HOME/lib/kxml2-2.3.0.jar:$APP_HOME/lib/httpmime-4.1.jar:$APP_HOME/lib/annotations-12.0.jar:$APP_HOME/lib/sdklib-26.0.0-dev.jar:$APP_HOME/lib/guava-22.0.jar

And that's pretty much it, should solve the issue.

I did these steps because flutter doctor --android-licenses was giving me issues. And this fixed it.

Saifur Rahman Mohsin
  • 740
  • 1
  • 10
  • 29
2

(WINDOWS)

If you have installed Android Studio already go to File >> Project Structure... >> SDK Location.

Go to that location + \cmdline-tools\latest\bin Copy the Path into Environment Variables

than it is OK to use the command line tool.

niek tuytel
  • 189
  • 2
  • 9
1

The only working solution for me is to use the java shipped with the Android studio.

set the JAVA_HOME to /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home

in .bashrc

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

If you are using fish shel, put this in ~/.config/fish/config.fish

set -gx JAVA_HOME /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home

(This is for mac, but I am sure it should work with linux and windows by setting the correct path)

RameshVel
  • 60,384
  • 28
  • 166
  • 207
  • This might interfere with other application trying to use the Original/Non-OpenJDK version of Java from Oracle. Eventhough OpenJDK is more than capable, some might need the other one as well. – Jemsheer K D May 03 '20 at 08:14
1

JDK 13.0.1, Android SDK 29 , Windows 10

Basically i tried everything, but the most effective and only 1 solution that worked for me was to downgrade to jdk 1.8. I dont why, it is early 2020 and have to downgrade to 1 year old jdk version against latest flutter version. Maybe problem is in windows version, cause jdk 13.0.1 worked for me on macOS 10.15.2. Hope this solution works.

Download Link (JDK 1.8.0): https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Kedar Sukerkar
  • 833
  • 8
  • 17
  • Java 8 was released in march 2014. So it is a bit more than 1 year old... – pqnet May 18 '20 at 18:05
  • yeah..but Oracle policy has changed since Java 8.....it is not free for organisation anymore. So, everyone are forced to use Java8 – Kedar Sukerkar May 18 '20 at 22:18
  • The problem is that newer java runtimes (9+) do not have javax libraries, you are supposed to ship them with your application. So software written expecting to run on java 8 and before do not ship these libraries, and thus won't work on 9+. The reason, as you guessed, is to make the standard JDK fully open source (these libraries are not GPL), so I would say that the license terms improved. – pqnet May 19 '20 at 11:57
1

Define home directories of different JDK versions in your .bashrc or .zshrc:

export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_14_HOME=$(/usr/libexec/java_home -v14)

First of all use JDK version 8. Put this line the top of sdkmanager file:

export JAVA_HOME=$JAVA_8_HOME

Switch back to JDK version 14. Put this line the bottom of sdkmanager file:

export JAVA_HOME=$JAVA_14_HOME
Gabor G
  • 11
  • 2
1

Apparently if you use "commandlinetools" version greater than 3.6.0 you may use JDK11+ to install Android SDK components.

They are available here: https://developer.android.com/studio#command-tools

Official issue tracker saying it is fixed: https://issuetracker.google.com/issues/122210344#comment11

Mike Hardy
  • 1,148
  • 2
  • 9
  • 29
0

https://adoptopenjdk.net currently supports all distributions of JDK from version 8 onwards. For example https://adoptopenjdk.net/releases.html#x64_win

Here's an example of how I was able to use JDK version 8 with sdkmanager and much more: https://travis-ci.com/mmcc007/screenshots/builds/109365628

For JDK 9 (and I think 10, and possibly 11, but not 12 and beyond), the following should work to get sdkmanager working:

export SDKMANAGER_OPTS="--add-modules java.se.ee"
sdkmanager --list
mmccabe
  • 1,989
  • 1
  • 19
  • 24
  • 1
    Any idea of how to fix this for SDK 12? – Richie May 03 '19 at 12:52
  • @Richie Did you solve this, I too have Java 12 and running into this issue and nothing that is posted here is helping. – james emanon Jun 16 '19 at 05:09
  • 1
    As I recall, I think you have to download the jar file that contains java.se.ee and add it to the path (or something similar). AFAIK Oracle unbundled J2EE-related jars from the JDK for 12 and beyond. Did not test this with sdkmanager. – mmccabe Jun 17 '19 at 06:42
  • @jamesemanon I did not manage to solve it. Try the above suggestion – Richie Jul 15 '19 at 06:39
0

Another solution possible to this error is check your Java version, maybe you can solve it downloading this jdk oracle-jdk-8, this was my mistake :P

Pedro Molina
  • 429
  • 6
  • 7
0

You just need to install jaxb har files and include in the classpath. this works in java 11 to 12 latest.

To those who are looking for the fix i made some gist in github hope this help. and the links are provided also.

https://gist.github.com/Try-Parser/b7106d941cc9b1c9e7b4c7443a7c3540

HuntsMan
  • 722
  • 5
  • 16
0

I download Java 8 SDK

  1. unistall java sdk previuse
  2. close android studio
  3. install java 8
  4. run-> cmd-> flutter doctor --install -licenses and after
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.19041.388], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.47.3)
[!] Connected device
    ! No devices available

! Doctor found issues in 1 category
display  and finish
craigcaulfield
  • 2,976
  • 10
  • 26
  • 33
0

For users on mac, I solved an issue similar to this by modifying my zshrc file and adding the following (although your java_home might be configured differently) :

export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/YOURUSER/Library/Android/sdk
export PATH=$PATH:/Users/YOURUSER/Library/Android/sdk/tools
export PATH=$PATH:%ANDROID_HOME%\tools
export PATH=$PATH:/Users/YOURUSER/Library/Android/sdk
0

enter image description here

I just add "Android SDK Command-line Tools (latest)" and this solved my issue.

Originally from here: https://github.com/flutter/flutter/issues/56778#issuecomment-742639036

Anton Starcev
  • 400
  • 5
  • 7
-1

If you are using flutter, Run this command flutter doctor --android-licenses

-1

Go to {SDK_FOLDER}/lib/_/ (underscore folder). Copy all the files from the _ folder to its parent folder /lib.

-2

It's very simple, just export the JAVA_HOME environment variable, set to the path of your JDK installation.

I installed Java manually on Ubuntu, and so for me this looks like:

export JAVA_HOME="$HOME/pkg-src/jdk1.8.0_251"

And make sure it exists in your path too...

export PATH="$PATH:$JAVA_HOME"
brianarpie
  • 301
  • 2
  • 7