Sdkmanager "Error: Could not find or load main class com.android.sdklib.tool.sdkmanager.SdkManagerCli" on Windows
Asked Answered
K

12

16

I am trying to install Flutter without Android Studio and here is what I did:

  • Installed Java 8
  • Installed and Unzipped Flutter SDK to C:\src.
  • Installed and Unzipped Android Command-line tools (sdkmanager) to C:\Android.
  • Added the environment variables (ANDROID_HOME: C:\Android)

Now when I try to run sdkmanager to install Android SDK, I get this error:

"Error: Could not find or load main class com.android.sdklib.tool.sdkmanager.SdkManagerCli"

I have tried reinstalling Flutter sdk and the sdkmanager with no luck.

Here is Flutter Doctor's output: Flutter version: 1.12.13, Dart version: 2.7, Flutter can't find Android SDK

sdkmanager error: "Error: Could not find or load main class com.android.sdklib.tool.sdkmanager.SdkManagerCli"

Keiko answered 17/3, 2020 at 17:27 Comment(0)
M
11
  1. Download the SDK tools ZIP (Under Command Line Tools in https://developer.android.com/studio).
  2. Unzip using 7zip. Avoid using the default windows extractor - that doesn't do the extraction correctly.
  3. After unzipping using 7zip, place the contents into the sdk folder (C:\Users\<username>\AppData\Local\Android\Sdk\tools\bin and C:\Users\<username>\AppData\Local\Android\Sdk\lib) and run sdkmanager on command prompt.
Maidenhood answered 2/8, 2020 at 12:45 Comment(1)
It seems that nowadays this needs to be in cmdline-tools/latest instead of just tools. – Nahshun
A
16

Open the sdkmanager.bat in a text editor and add echo %CLASSPATH% just below the CLASSPATH=%APP_HOME%\...\sdkmanager-classpath.jar. Then run sdkmanager --help which will echo the CLASSPATH of the required file. And check whether is it the valid path.

In my case, it was the wrong path,

enter image description here

It said my sdkmanger-classpath.jar is in lib folder. But it was not! It was actually inside the lib/_ folder. So as the simple solution what I did was copy the content in side lib/_ folder to lib. Then it worked fine!

Ailis answered 21/6, 2020 at 2:32 Comment(1)
BIG ITEM here is using Windows to UNZIP the archive was the failure. Using 7-zip properly has the files in their respective folders. Good alternate find on the path though. – Standing
M
11
  1. Download the SDK tools ZIP (Under Command Line Tools in https://developer.android.com/studio).
  2. Unzip using 7zip. Avoid using the default windows extractor - that doesn't do the extraction correctly.
  3. After unzipping using 7zip, place the contents into the sdk folder (C:\Users\<username>\AppData\Local\Android\Sdk\tools\bin and C:\Users\<username>\AppData\Local\Android\Sdk\lib) and run sdkmanager on command prompt.
Maidenhood answered 2/8, 2020 at 12:45 Comment(1)
It seems that nowadays this needs to be in cmdline-tools/latest instead of just tools. – Nahshun
E
7

On Windows Server 2019, using commandlinetools-win-6609375_latest.zip, we faced the same issue. We placed package inside Program File (i.e. C:\Program Files\Android\cmdline-tools\tools\bin).

It seems this will not work if there is space in the path. So we placed it in folder path without spaces (i.e. C:\Android\cmdline-tools\tools\bin) and it is working fine!πŸŽ‰

Exceptive answered 5/8, 2020 at 11:28 Comment(3)
This was happening to me too. Instead of moving it to a different path, I edited a line in sdkmanager.bat, just putting quotes around the toolsdir argument. Like this: set DEFAULT_JVM_OPTS=-Dcom.android.sdklib.toolsdir="%~dp0\.." – Cenogenesis
Thank you! I had the same problem with a space in the path – Copyhold
@Cenogenesis After three hours this helped – Craig
P
4

As @Chrishan wrote Avoid using default windows extractor.

You can use the PowerShell:

Expand-Archive  commandlinetools....zip  C:\Android\Sdk
Panta answered 4/8, 2020 at 19:13 Comment(0)
J
3

It worked for me. Make sure there exists no space in the path folders in the path to SDK. example: C:\Users\Anu Jadav\xyz\

like above in username I had space, Initially, I was not able to execute flutter doctor --android-licenses.

After I renamed the username. Then it worked like a charm. I renamed my username using this reference video

.

Justifier answered 28/11, 2020 at 15:54 Comment(0)
X
3

Go to android sdk folder.

Open cmdline-tools folder.

Then rename "latest" folder as "tools".

Default name: (Path to sdk)\AndroidSDK\cmdline-tools\latest

After rename: (Path to sdk)\AndroidSDK\cmdline-tools\tools

Then; run flutter doctor command using terminal.

Xanthine answered 8/2, 2021 at 14:5 Comment(2)
This answer help me solve my problem. I've moved the SDK from one path to another. Thanks @Lojith – Furgeson
After doing this, flutter doctor gives the same unfavourable output. Except now on running flutter doctor --android-licenses the error has changed to: "Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this." – Obnoxious
H
1

I fixed by adding '--sdkroot ' pointing to the root folder (i.e. parent of bin). e.g. % ./bin/sdkamanager --sdkroot .

Heimer answered 2/4, 2020 at 20:23 Comment(1)
The truth is... I was giving Win10 a try but I didn't really like it, so I am back to Linux now hence can't try your answer. I am accepting tho πŸ‘ – Keiko
L
1

I have solved this issue by doing so many things.

  1. Download Java 8.
  2. Set EV to the Java 8 folder.
  3. Download SDK in separate folder.
  4. While setting EV of SDK make it sure there is no whitespace in the path.
  5. Set path of the following in user variables:
    • Build-tools.
    • platform-tools.
    • platform
  6. Now enter flutter doctor --android-licenses
    • press y multiple times and at last your licenses will be accepted.
  7. Check whether your license accepted or not by using flutter doctor
Luckless answered 2/12, 2020 at 14:14 Comment(0)
X
0

Firstly open android studio and from there open sdk manager and install required sdk tools then -

  1. Make sure there exist no space in the path folders in the path to sdk.
  2. Add ANDROID_SDK_ROOT variable to the Users variable with value as the path for sdk folder e.g. C:\users\xyz\android\sdk (there should be no space in these folder names).
  3. Add this path to the path variable in the system variable.
  4. Run flutter doctor in the command prompt.
  5. Run flutter doctor --android-licenses.
  6. Accept the licenses by entering 'y'.

--The setup should be done and just check by running flutter doctor.

Xanthochroid answered 23/10, 2020 at 17:29 Comment(0)
J
0

I fixed this issue by removing a space in my path where i had extracted the cmd tools. My path was:

C:\Cordova Tools\cmdline-tools

there was a space in folder name "Cordova Tools". I removed the space and changed folder name like:

C:\Cordova_Tools\cmdline-tools

And it worked just perfectly.

Jamieson answered 7/2, 2021 at 10:5 Comment(0)
O
0

The problem may be due to the fact that your sdk installation failed severally before finally installing. To check if that is the case, go the path C:\Users<username>\AppData\Local\Android\Sdk and if there are tools, tools-1, ... The necessary files are installed in the last of this folder. So, rename the supposed original folder - tools, to something else and change the name of the one in which the installation is done to tools. This should solve the problem.

Ornie answered 5/4, 2021 at 4:11 Comment(1)
The question already has an accepted answer. – Pleuro
B
0

download jdk 11 and update ev JAVA_HOME to C:\Program Files\Java\jdk-11.0.17

Berry answered 27/1, 2023 at 1:23 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.