Novellizator
Novellizator

Reputation: 14883

Failed to install android-sdk: "java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema"

When installing the android sdk tools the following error is emitted:

java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

Why is this happening and how can it be fixed?

Debug output:

$ java --version
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
$ brew cask install android-sdk
==> Caveats
We will install android-sdk-tools, platform-tools, and build-tools for you.
You can control android sdk packages via the sdkmanager command.
You may want to add to your profile:
  'export ANDROID_SDK_ROOT=/usr/local/share/android-sdk'

This operation may take up to 10 minutes depending on your internet connection.
Please, be patient.

==> Satisfying dependencies
==> Downloading https://dl.google.com/android/repository/sdk-tools-darwin-3859397.zip
Already downloaded: /Users/tomasnovella/Library/Caches/Homebrew/Cask/android-sdk--3859397,26.0.1.zip
==> Verifying checksum for Cask android-sdk
==> Installing Cask android-sdk
==> 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
Error: Command failed to execute!

==> Failed command:
/usr/local/Caskroom/android-sdk/3859397,26.0.1/tools/bin/sdkmanager tools platform-tools build-tools;26.0.1

==> Standard Output of failed command:


==> Standard Error of failed 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.SdkManagerCli.main(SdkManagerCli.java:117)

Upvotes: 564

Views: 549837

Answers (30)

thebiggestlebowski
thebiggestlebowski

Reputation: 2779

As others have mentioned, this can be fixed by using java 8. However, my android projects needs java 11. My solution was that anytime I need to use sdkmanager, I set JAVA_HOME to java 8. After I'm done with sdkmanager, I revert JAVA_HOME back to java 11.

Upvotes: 0

valdeci
valdeci

Reputation: 15237

To solve this error, you can downgrade your Java version.

Or export the following option on your terminal:

Linux/Mac:

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 export 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

To save it permanently, you can export the JAVA_OPTS in your profile file on Linux (.zshrc, .bashrc, 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, it is a good idea to downgrade your Java version or wait for a Flutter update.

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

Upvotes: 99

JP Ventura
JP Ventura

Reputation: 5732

TL; DR

The following steps will not only install Android Studio IDE but also make all command line available at your shell:

  1. Install Android Studio at /opt/jetbrains/studio, not at your home directory
  2. During the custom installation, set your ANDROID_HOME as /opt/google/android
  3. Configure the Android environment variables
export ANDROID_HOME=/opt/google/android

ANDROID_CMDLINE_TOOLS=${ANDROID_HOME}/cmdline-tools/latest/bin
ANDROID_PLATFORM_TOOLS=${ANDROID_HOME}/platform-tools
ANDROID_TOOLS=${ANDROID_HOME}/tools

# Latest Android NDK version at moment is 25.2.9519653
ANDROID_NDK=${ANDROID_HOME}/ndk/25.2.9519653

export PATH=${ANDROID_CMDLINE_TOOLS}:${ANDROID_NDK}:${ANDROID_PLATFORM_TOOLS}:${ANDROID_TOOLS}:${PATH}
  1. Create a symbolic link
ln -s /opt/google/studio/bin/studio.sh /usr/local/bin/studio

The steps above were performed with javac version 21.0.3

Description

According to the Filesystem Hierarchy Standard, /opt is for "the installation of add-on application software packages", while /usr/local is "for use by the system administrator when installing software locally".

However, unlike /usr/local, POSIX environment variables will not be automatically read.

Thus do the following steps:

  1. Install your Android Studio at /opt/jetbrains/studio
  2. Install your Android SDK at /opt/google/android
  3. Configure your shell environment variables

Why? Because they allow:

  1. Android Studio be available all users of the same workstation
  2. If you are an organization SysAdmin, you can clone /opt to all workstations
  3. If /opt is into a separated partition, your tools will be preserved if you reinstall or change POSIX OS

Install Android Studio

Download the latest version of Android SDK

Add your user into adm group. For example, do at Ubuntu shell:

sudo usermod -a -G adm $(whoami)

Then create the directories ensuring adm my write into them

sudo mkdir -p /opt/google/android
sudo mkdir /opt/jetbrains
sudo chown root:adm -R /opt
sudo chmod ug+w /opt

Download the latest Android Studio version and unpack it into /opt

cd ~/Downloads/
wget https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2024.1.1.12/android-studio-2024.1.1.12-linux.tar.gz

then unpack it into /opt/jetbrains/studio

cd /opt/jetbrains
sudo tar -xvzf ~/Downloads/android-studio-2024.1.1.12-linux.tar.gz 
sudo mv android-studio studio
sudo chown root:adm -R studio
rm ~/Downloads/android-studio-2024.1.1.12-linux.tar.gz

Install Android SDK

When you run /opt/jetbrains/studio.sh for the first time, do a custom install

Android Studio Custom Install

and specify the ANDROID_HOME location as /opt/google/android

Android Home

Configure command line tools

If you are using bash, add into /etc/profile

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

for Z shell users, at into /etc/zshenv

#!/usr/bin/env zsh

if [ -d /etc/zshenv.d ]; then
  for i in /etc/zshenv.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
 fi

Then write into android.sh the following environment variables:

export ANDROID_HOME=/opt/google/android

ANDROID_CMDLINE_TOOLS=${ANDROID_HOME}/cmdline-tools/latest/bin
ANDROID_PLATFORM_TOOLS=${ANDROID_HOME}/platform-tools
ANDROID_TOOLS=${ANDROID_HOME}/tools

# Latest Android NDK version at moment is 25.2.9519653
ANDROID_NDK=${ANDROID_HOME}/ndk/25.2.9519653

export PATH=${ANDROID_CMDLINE_TOOLS}:${ANDROID_NDK}:${ANDROID_PLATFORM_TOOLS}:${ANDROID_TOOLS}:${PATH}

Finally create a shortcut so you may invoke the IDE at command line:

ln -s /opt/google/studio/bin/studio.sh /usr/local/bin/studio

Command Line Tools

Play with some commands at your preferred shell:

$ avdmanager 

Usage:
      avdmanager [global options] [action] [action options]
      Global options:
  -s --silent     : Silent mode, shows errors only.
  -v --verbose    : Verbose mode, shows errors, warnings and all messages.
     --clear-cache: Clear the SDK Manager repository manifest cache.
  -h --help       : Help on a specific command.

Valid actions are composed of a verb and an optional direct object:
-   list              : Lists existing targets or virtual devices.
-   list avd          : Lists existing Android Virtual Devices.
-   list target       : Lists existing targets.
-   list device       : Lists existing devices.
- create avd          : Creates a new Android Virtual Device.
-   move avd          : Moves or renames an Android Virtual Device.
- delete avd          : Deletes an Android Virtual Device.

or

$ sdkmanager 
Usage:
  sdkmanager [--uninstall] [<common args>] [--package_file=<file>] [<packages>...]
  sdkmanager --update [<common args>]
  sdkmanager --list [<common args>]
  sdkmanager --list_installed [<common args>]
  sdkmanager --licenses [<common args>]
  sdkmanager --version

With --install (optional), installs or updates packages.
    By default, the listed packages are installed or (if already installed)
    updated to the latest version.
With --uninstall, uninstall the listed packages.

    <package> is a sdk-style path (e.g. "build-tools;23.0.0" or
             "platforms;android-23").
    <package-file> is a text file where each line is a sdk-style path
                   of a package to install or uninstall.
    Multiple --package_file arguments may be specified in combination
    with explicit paths.

With --update, all installed packages are updated to the latest version.

With --list, all installed and available packages are printed out.

With --list_installed, all installed packages are printed out.

With --licenses, show and offer the option to accept licenses for all
     available packages that have not already been accepted.

With --version, prints the current version of sdkmanager.

Common Arguments:
    --sdk_root=<sdkRootPath>: Use the specified SDK root instead of the SDK
                              containing this tool

    --channel=<channelId>: Include packages in channels up to <channelId>.
                           Common channels are:
                           0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary).

    --include_obsolete: With --list, show obsolete packages in the
                        package listing. With --update, update obsolete
                        packages as well as non-obsolete.

    --newer: With --list, show only new and/or updatable packages.

    --no_https: Force all connections to use http rather than https.

    --proxy=<http | socks>: Connect via a proxy of the given type.

    --proxy_host=<IP or DNS address>: IP or DNS address of the proxy to use.

    --proxy_port=<port #>: Proxy port to connect to.

    --verbose: Enable verbose output.

* If the env var REPO_OS_OVERRIDE is set to "windows",
  "macosx", or "linux", packages will be downloaded for that OS.

Upvotes: 0

A T
A T

Reputation: 13826

Opening Android projects in IDEA instead of Android Studio gave me this error.

Solution:

  1. Install Android SDK from the IDEA window
  2. It'll say "nothing to do" as the SDK is already downloaded and installed
  3. The licenses will automatically be accepted and now you can use IDEA for your Android projects

Upvotes: 0

Priyansh jain
Priyansh jain

Reputation: 1422

While building the flutter application an error occurred saying android sdk licenses not accepted. So, while accepting the license this error occurred.

Reason for this error in my case was I haven't installed sdkmanager command line tools which is required to accept the license.

So, to install command line tools easiest way is:

  1. Open android studio.

  2. Open SDK Manager (For Old Android Studio): For older version of Android studio

  3. Open SDK Manager (For New Android Studio): For newee version of Android studio

  4. Select SDK tools inside it in bar.

  5. Tick the option Android SDK Command-line Tools (latest)

  6. Apply it.

  7. Run flutter doctor -android-licenses if using flutter or you can continue with the process where the error occurred.

Upvotes: 21

EdYuTo
EdYuTo

Reputation: 6854

Just had this error, solved by downloading the Android SDK Command-line Tools (latest) on Android Studio, under Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools and re-running flutter doctor --android-licenses

NOTE: For Android Studio Android Studio Giraffe | 2022.3.1 Patch 1, find these setting under File > Settings and, in the left panel, Languages & Frameworks > Android SDK and finally select the SDK Tools.

Android SDK path on Android Studio

Command-line Tools

Finally, add the new tools to your PATH, in your .bashrc, .zshrc or similar, before the obsolete tools:

export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin

Upvotes: 608

inspiredMichael
inspiredMichael

Reputation: 388

I know this is an old question, however, another way to fix this error is by connecting an Android phone to your laptop (i.e. run the app on a physical device). Ensure the USB debug mode is enabled. enter image description here

Upvotes: 0

Sarah A
Sarah A

Reputation: 1233

If you're on Mac OS, and you don't want to change your Java version (I don't), you can temporarily change the version in your shell:

First run

/usr/libexec/java_home -V

Then pick a major version if you have it installed, otherwise install it first:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Now you can run sdkmanager.

Upvotes: 37

spassvogel
spassvogel

Reputation: 3541

I had a similar problem this morning (trying to build for Android using Unity3D). I ended up uninstalling JDK9 and installing Java SE Development Kit 8u144.

  1. brew cask uninstall java # uninstall java9
  2. brew tap homebrew/cask-versions
  3. brew cask install java8 # install java8
  4. touch ~/.android/repositories.cfg # without this file, error will occur on next step
  5. brew install --cask android-sdk

Upvotes: 187

Thomas Fischer
Thomas Fischer

Reputation: 1514

This question has multiple answers depending on the underlying issue. There are also multiple answers that indirectly fix the actual problem.

The core issues are:

  1. Android SDK tools have issues with the latest Oracle JDK. You can use the latest Open JDK. (The latest OpenJDK comes with Android Studio.)

  2. You don't have the latest Android SDK command line tools installed.

  3. You have the latest Android SDK command line tools installed, but you are using E:\Android\Sdk\tools\bin instead of E:\Android\Sdk\cmdline-tools\latest\bin.

Here are systematic steps to identify and fix any of the above issues that you may have.

  1. Point environment variables to your OpenJDK installation in Android Studio. Depending on your installation that is found here: E:\Program Files\Android\Android Studio\jre. You have to go through all the necessary variables like PATH, JAVA_HOME, JAVA_BIN etc and make sure that they all point to your OpenJDK.

Note: You don't have to uninstall/reinstall JDKs. That simply probably fixes your variables above as a side effect.

  1. Check that your environment variables are correct (Windows: echo %JAVA_HOME%, echo %PATH%, where javac, etc.)

  2. Go to Android Studio. In Settings, navigate to "Appearances & Behavior > System Settings > Android SDK." Install "Android SDK Command Line Tools."

  3. In the shell, go to E:\Android\Sdk\cmdline-tools\latest\bin and run sdkmanager --install "cmdline-tools;latest"

Additional troubleshooting tips: I had Android environment variables messed up as well. Run 'flutter doctor -v' and the output will help you troubleshoot additional environment configuration issues.

Upvotes: 2

Nati
Nati

Reputation: 121

For Windows users looking for solution

Option 1 Install the cmdline-tools from within the Android Studio SDK manager

enter image description here


Option 2 Download from this link https://developer.android.com/studio#cmdline-tools

Then follow this tutorial below on how to set it up https://www.youtube.com/watch?v=wvi03sOBKWQ


Next copy the path to where the cmdline-tools was installed towards the bin folder

Using Android Studio SDK Manager
The cmdline-tools is installed under the Android SDK Location
Example:
C:\Users\%username%\AppData\Local\Android\Sdk\cmdline-tools\latest\bin


Then paste the path in to the Environment Variable Path

Control Panel> Set the View By to Large Icons>System>Under 'Related Settings' on the right side choose Advanced System Settings>Environment Variables

From here you add the path under System variables enter image description here

Make sure that the cmdline-tools path is above the tools path (highlighted in the picture in red box) if they exist.

Select the Path>Edit>Select the cmdline-tools path (highlighted in blue) >Move Up

Upvotes: 4

Rohan Devaki
Rohan Devaki

Reputation: 3279

  • I also had this error
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
  • then instead of uninstalling the latest java environment, (in my case it is java 13)
  • and installation of java 8,
  • I have done the following steps
  • open the android studio > go to configure > select sdk manager > go to sdk tools > make a tick on android sdk command line tools >apply > and wait for installation

enter image description here

enter image description here enter image description here

  • restart the command line tool enter image description here

  • enter the command flutter doctor

  • enter the command flutter doctor --android-licenses

  • and accept all the licenses by typing y.

enter image description here

Upvotes: 135

Katu
Katu

Reputation: 1564

Got this error running "flutter doctor --android-licenses" In Windows 10. I solved it creating these two environment variables

ANDROID_SDK_ROOT
C:\Users\youruser\AppData\Local\Android\Sdk

ANDROID_SDK_HOME
C:\Users\youruser\.android

Refresh environment variables or reboot and then run the command again.

Upvotes: 0

Enrique Ren&#233;
Enrique Ren&#233;

Reputation: 598

In my case, I have Java 14 and need Java 8.

I'm in a Arch Linux and has installed jdk8-openjdk jre8-openjdk https://www.archlinux.org/packages/extra/x86_64/java8-openjdk/

For Debian users https://wiki.debian.org/Java, or Fedora https://docs.fedoraproject.org/en-US/quick-docs/installing-java/.

Install Java 8 (or desired version, in this case jdk8-openjdk jre8-openjdk) using your package manager before doing the following steps.


1. Figuring out where is my Java:

# which java
/usr/bin/java

2. Checking java files:

I can see all java files here are links to /usr/lib/jvm/default[something]. This means that the java command is linked to some specific version of java executable.

# ls -l /usr/bin/java*
lrwxrwxrwx 1 root root 37 May 16 06:30 /usr/bin/java -> /usr/lib/jvm/default-runtime/bin/java
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javac -> /usr/lib/jvm/default/bin/javac
lrwxrwxrwx 1 root root 32 May 16 06:30 /usr/bin/javadoc -> /usr/lib/jvm/default/bin/javadoc
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javah -> /usr/lib/jvm/default/bin/javah
lrwxrwxrwx 1 root root 30 May 16 06:30 /usr/bin/javap -> /usr/lib/jvm/default/bin/javap

3. Checking the default and default-runtime

Here I could see the default version was linked to 14 (unique installed version).

# cd /usr/lib/jvm
# ls -l
lrwxrwxrwx 1 root root   14 Aug  8 20:44 default -> java-14-openjdk
lrwxrwxrwx 1 root root   14 Aug  8 20:44 default-runtime -> java-14-openjdk
drwxr-xr-x 7 root root 4096 Jul 19 22:38 java-14-openjdk
drwxr-xr-x 6 root root 4096 Aug  8 20:42 java-8-openjdk

4. Switching the default version

First, remove the existing default and default-runtime which linked to java-14 version.

# rm default default-runtime

Then, create new links to the desired version (in this case, java-8).

# ln -s java-8-openjdk default
# ln -s java-8-openjdk default-runtime

The strategy is to make links to the desired version of software (java8 in this case) using ln -s above. Then, this links are linked to the binaries inside the java bin directory (without changing the $PATH environment variable!)


Or you might be wanted to change the Java version using archlinux-java command instead with more safely approach: https://wiki.archlinux.org/index.php/Java

Upvotes: 5

G00fY
G00fY

Reputation: 5277

Update 2019-10:

As stated in the issue tracker, Google has been working on a new Android SDK Command-line Tools release that runs on current JVMs (9, 10, 11+) and does not depend on deprecated JAXB EE modules!

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 available at Googles Downloads-Website. These tools are newer than those linked above.

Upvotes: 63

mr.M
mr.M

Reputation: 899

Updated my current Android SDK and everything worked like a charm.

Upvotes: 0

Canberk Sinangil
Canberk Sinangil

Reputation: 1052

In my case I didn't have the required sdk version installed on my machine.

So make sure that you have installed the sdk version which is given in the error.

Here you can navigate check & install via Android Studio.

Android Stuido SDK Manager

Upvotes: 3

Steven
Steven

Reputation: 1243

When using Linux, an easy option is installation of JDK version 8 then selecting it as the default using:

sudo update-alternatives --config java

Upvotes: 28

chendu
chendu

Reputation: 819

My Java version is 15.0.1 . For the OS Mac.

and this is how i fixed the issue.

  1. downloaded zip: jaf-1_1_1.zip from: https://download.oracle.com/otn-pub/java/jaf/1.1.1/jaf-1_1_1.zip?AuthParam=1609860571_68ca6f30491c76e81970a3849504fb6a

  2. downloaded the zip: jaxb-ri-2.3.1.zip from: https://download.oracle.com/otn-pub/java/jaf/1.1.1/jaf-1_1_1.zip?AuthParam=1609860571_68ca6f30491c76e81970a3849504fb6a

  3. unziped into a folder: ~/jars/ . exported classpath as follows

export  
 CLASSPATH=~/jars/FastInfoset.jar:~/jars/activation.jar:~/jars/codemodel.jar:~/jars/dtd-parser.jar:~/jars/istack-commons-runtime.jar:~/jars/istack-commons-tools.jar:~/jars/jaf-1.1.1:~/jars/jaf-1_1_1.zip:~/jars/javax.activation-api.jar:~/jars/jaxb-api.jar:~/jars/jaxb-jxc.jar:~/jars/jaxb-ri:~/jars/jaxb-ri-2.3.1.zip:~/jars/jaxb-runtime.jar:~/jars/jaxb-xjc.jar:~/jars/relaxng-datatype.jar:~/jars/rngom.jar:~/jars/stax-ex.jar:~/jars/txw2.jar:~/jars/xsom.jar
  1. next edit the file: cd ~/Library/Android/sdk/tools/bin/sdkmanager change the CLASSPATH to the below

CLASSPATH=$CLASSPATH:$APP...

save the file and run the command again.

Upvotes: 0

funder7
funder7

Reputation: 1830

This question has numerous answers, and they're all different due to users installing different toolchains and using different Java versions.

The recommended way of using Android development toolchain, or at least the one that I suggest to use, is to follow what's stated in Android Studio documentation:

You should always keep your Build Tools component updated by downloading the latest version using the Android SDK Manager.

Android studio allows you to easily manage installed SDKs & build tools, yes, it requires some space on your hard drive, but it will save you some time. Once you get familiar with how it works, then you can think of installing command-line tools only.

If there's no particular reason of using older Java version, use the latest (stable) version, you will have interesting new features, and also the compiled application will benefit from all the new optimizations.

Fresh install

  1. Delete your local Android folder, usually in the home directory
  2. Download Android studio
  3. Once installed, open Settings, Search Android SDK and open it
  4. In SDK Platforms select the target Android version for your app
  5. In SDK Tools tab, select Android SDK Build-Tools, Android SDK Command-line Tools (latest), Android Emulator, Android SDK Platform-Tools
  6. Before pressing OK, check that Android SDK Location path is correct for you
  7. Press OK and let Android Studio download & install everything

(Optional) if you need to use the installed binaries from command line, be sure to add their folder into your PATH variable. If you use Android studio, it's should not be required though.

I've got Java 14 installed on my machine, anyway you can use the jre shipped with Android Studio.

Upvotes: 3

farhan meo
farhan meo

Reputation: 47

I was having the same issue and had installed openjdk-8-jdk as suggested. Checking javac -version resulted in the correct version, but java -version showed version 11.

The solution was to use:

sudo update-alternatives --config java

and select version 8 from the menu.

Upvotes: 0

xarlymg89
xarlymg89

Reputation: 2617

As @steven pointed out, install Java 8 (here a link for Ubuntu 16.04, 18.04 and 20.04/20.10 https://computingforgeeks.com/how-to-install-java-8-on-ubuntu/) and then set it as the default Java version with this command:

sudo update-alternatives --config java

Upvotes: 1

inf3cti0n95
inf3cti0n95

Reputation: 106

No need to uninstall your other java version(s) that's already installed on your machine. Whenever required, you can conveniently use the utility 'update-alternatives' to choose the Java runtime that you wish to activate. It will automagically update the required symbolic links.

You just need to run the below command and select the version of your choice. That's all!

sudo update-alternatives --config java

Upvotes: 1

locropulenton
locropulenton

Reputation: 4853

TLDR; Try setting JAVA_HOME worked fine for me on OSX

export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

To install the JDKs 8 ( LTS ) from AdoptOpenJDK:

# brew tap adoptopenjdk/openjdk

brew cask install adoptopenjdk/openjdk/adoptopenjdk8

Upvotes: 4

jbg
jbg

Reputation: 5266

As of the latest version of the Android command-line tools (2.1 as of this writing), it is no longer necessary to patch sdkmanager nor to downgrade to an ancient version of Java.

Simply update your SDK packages and switch your command-line tools to the latest release, which will track new versions as they come:

sdkmanager --update
sdkmanager 'cmdline-tools;latest'
sdkmanager --uninstall 'cmdline-tools;1.0'

You may need to provide the full path to sdkmanager if it's not on your PATH, and you may need to adjust your PATH afterwards if it was referring to the 1.0 tools explicitly.

Upvotes: 5

Will59
Will59

Reputation: 1863

In my case, I need both JDK 8 (trying to use the AVD and SDK manager in Qt under ubuntu) and 11 for different tools. Removing version 11 is not an option.

The 'JAVA_OPTS' solutions did not do anything. I don't really like the export JAVA_HOME, as it might force you do launch whatever tool calls these utils from the same shell (like Qt), or force you to make this permanent, which is not convenient.

So for me the solution is quite simple. Add something like this in the second line of ~/Android/tools/bin/sdkmanager and ~/Android/tools/bin/avdmanager:

JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"

(or whatever the path is to your rev 8 jdk).

With this, these command line tools work in a stand alone mode, they work also when called by other tools such as Qt, and jdk 11 is still the system default for others. No need to mix libs etc...

The only downside is that any update to these command line tools will erase these modifications, which you will have to put back in.

Upvotes: 6

zishan paya
zishan paya

Reputation: 513

Best way is to use below command

   $ wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
   $ unzip \platform-tools-latest-linux.zip
   $ sudo cp platform-tools/adb /usr/bin/adb
   $ sudo cp platform-tools/fastboot /usr/bin/fastboot

Now run adb version to verify it’s been updated.

Upvotes: 1

THE_BLESSED_MEDIUM
THE_BLESSED_MEDIUM

Reputation: 1034

I faced the same problem. Though I am a little bit backdated developer (Still using windows to develop :P)

To solve this issue on windows :

STEP 1: Install jdk 8 if it wasn't installed (jdk 9 or 11 doesn't work but you may have them installed for using in other dev uses).

Very simple using Chocolatey:

choco install jdk8

(If installed using Chocolatey, skip steps 2 and 3)

STEP 2: Go to the Environment variables settings and set JAVA_HOME TO jdk 8's installation directory.

JAVA_HOME

STEP 3: Go to path variable and add bin directory of jdk 8 and move it to top.

Path_varriable

STEP 4: Close any open terminal sessions and restart a new session

OPTIONAL STEP 5: Depending on your objective in the terminal run (may need to add sdkmanager to path or just navigate to the directory):

sdkmanager --update

That's all! :O Enjoy fluttering! :D

Upvotes: 12

Milan Adhikari
Milan Adhikari

Reputation: 119

I had recently solved this problem by uninstalling the higher version of JDK and installing JDK 8. After installing the JDK you need to give the path. Then you need to open command prompt in "C:\Users\Milan Adhikari\AppData\Local\Android\Sdk\tools" and run "sdkmanager --update" which will update your sdk and then you need to run "flutter doctor --android-licenses" in cmd and accept all the licenses.
Now your problem should be solved.

Upvotes: 1

oori
oori

Reputation: 5711

On Mac/Linux use the following command:

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

Works for both JDK 9 and 10, without patching any script (sdkmanager, avdmanager).

For Java 11 see: https://stackoverflow.com/a/51644855/798165

Upvotes: 24

Related Questions