Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install sdkmanager in windows 10

I am trying to install the sdk manager alone for using it with Eclipse. I downloaded the zip file provided by google -

commandlinetools-win-6200805_latest.zip

from https://developer.android.com/studio

But as I try to run the sdkmanager.bat file it doesn't run and i am getting the following errors:

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

Please note that Java jdk path is set properly and there is no error with respect to that.

If you are interested to look at the bat file, here it is:

@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:"=%
@rem set JAVA_EXE=C:/Program Files/Java/jdk1.8.0_241/bin/java.exe
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\/sdkmanager-classpath.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

Any help appreciated

like image 639
truespan Avatar asked Mar 05 '20 11:03

truespan


People also ask

How do I fix Sdkmanager not found?

You need to open Android Studio then go to Tools > SDK Manager > SDK Tools tab, uncheck the option Hide Obsolete Packages. And install Android SDK Tools and Android SDK Command-line Tools.

Where is Sdkmanager installed?

The sdkmanager tool is provided in the Android SDK Command-Line Tools package.


1 Answers

TL;DR;

  • copy the content of tools/lib/_ to tools/lib
  • run sdkmanager commands with --sdk_root parameter.

Details

In the line 66 of the sdkmanager.bat, CLASSPATH is defined to be like this

set CLASSPATH=%APP_HOME%\lib\/sdkmanager-classpath.jar

and inside the lib directory, sdkmanager-classpath.jar is, oddly, under a subdirectory called -.

I tried to change the path in the batch file but it did not work, so I copied the files from ..../tools/lib/_ to ..../tools/lib and the error disappeard. However, a warning appeared:

Warning: Could not create settings
java.lang.IllegalArgumentException
        at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.<init>(SdkManagerCliSettings.java:428)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:152)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCliSettings.createSettings(SdkManagerCliSettings.java:134)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:57)
        at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)

According to this answer, I tried to pass the --sdk_root parameter which worked without problems:

sdkmanager --sdk_root=%ANDROID_HOME% --list
# %ANDROID_HOME% is the environment variable that contains the path of android
# sdk installation. Typically, would be:
# `C:\Users\<USERNAME>\AppData\Local\Android\Sdk\tools`

PS: even I was able to solve this, I would say that this answer is a workaround since the documentation does not mention anything about copying files to other path

like image 177
Odai Alali Avatar answered Oct 21 '22 04:10

Odai Alali