sdk管理器

sdk管理器

我的平台信息:

  • 操作系统:Windows 7(x86)
  • Java:jre1.8.0_111
  • SDK:tools_r25.2.3-windows.zip

我是不是使用 Android Studio;相反,我只需要用于 Apache Cordova 开发的 SDK。

我的问题:当我运行 时sdkmanager.bat,GUI 没有出现。相反,我得到了一个显示命令行选项(--list 等)的帮助输出。

在研究这个问题时,我读到某处说我应该android.bat直接运行。我照做了,然后 SDK 管理器 GUI 就出现了!

这是怎么回事sdkmanager.bat?为什么我需要运行它而不是android.bat像我现在这样直接运行?

编辑:

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
if "%@eval[2+2]" == "4" goto 4NT_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=%*
goto execute

:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\lib\sdklib-25.3.0-dev.jar;%APP_HOME%\lib\layoutlib-api-25.3.0-dev.jar;%APP_HOME%\lib\dvlib-25.3.0-dev.jar;%APP_HOME%\lib\repository-25.3.0-dev.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.0-dev.jar;%APP_HOME%\lib\kxml2-2.3.0.jar;%APP_HOME%\lib\annotations-25.3.0-dev.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% %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

android.bat内容:

@echo off
rem Copyright (C) 2007 The Android Open Source Project
rem
rem Licensed under the Apache License, Version 2.0 (the "License");
rem you may not use this file except in compliance with the License.
rem You may obtain a copy of the License at
rem
rem      http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem Useful links:
rem Command-line reference:
rem   http://technet.microsoft.com/en-us/library/bb490890.aspx

rem don't modify the caller's environment
setlocal enableextensions

rem Set up prog to be the path of this script, including following symlinks,
rem and set up progdir to be the fully-qualified pathname of its directory.
set prog=%~f0

rem Grab current directory before we change it
set work_dir=%cd%

rem Change current directory and drive to where the script is, to avoid
rem issues with directories containing whitespaces.
cd /d %~dp0


rem Check we have a valid Java.exe in the path.
set java_exe=
call lib\find_java.bat
if not defined java_exe goto :EOF

set jar_path=lib\sdkmanager.jar;lib\swtmenubar.jar

rem Set SWT.Jar path based on current architecture (x86 or x86_64)
for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery.jar') do set swt_path=lib\%%a

:MkTempCopy
    rem Copy android.bat and its required libs to a temp dir.
    rem This avoids locking the tool dir in case the user is trying to update it.

    set tmp_dir=%TEMP%\temp-android-tool
    xcopy "%swt_path%" "%tmp_dir%\%swt_path%" /I /E /C /G /R /Y /Q > nul
    copy /B /D /Y lib\common.jar         "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\commons-codec*     "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\commons-compress*  "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\commons-logging*   "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\dvlib.jar          "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\gson*              "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\guava*             "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\httpclient*        "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\httpcore*          "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\httpmime*          "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\layoutlib-api.jar  "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\org-eclipse-*      "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\sdk*               "%tmp_dir%\lib\"          > nul
    copy /B /D /Y lib\swtmenubar.jar     "%tmp_dir%\lib\"          > nul

    rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
    set tools_dir=%cd%
    cd /d "%tmp_dir%"

:EndTempCopy

rem The global ANDROID_SWT always override the SWT.Jar path
if defined ANDROID_SWT set swt_path=%ANDROID_SWT%

if exist "%swt_path%" goto SetPath
    echo ERROR: SWT folder '%swt_path%' does not exist.
    echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
    goto :EOF

:SetPath
rem Finally exec the java program and end here.
REM set REMOTE_DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
call "%java_exe% %REMOTE_DEBUG%" "-Dcom.android.sdkmanager.toolsdir=%tools_dir%" "-Dcom.android.sdkmanager.workdir=%work_dir%" -classpath "%jar_path%;%swt_path%\swt.jar" com.android.sdkmanager.Main %*

rem EOF

答案1

您不仅可以使用 GUI 工具来安装/更新/删除 SDK 组件,还可以使用命令行工具

sdk管理器

sdkmanager是一个命令行工具,允许您查看、安装、更新和卸载 Android SDK 的软件包。[...]

sdkmanager工具在 Android SDK 工具包(25.2.3 及更高版本)中提供,位于android_sdk/tools/bin/

它也可能适合编写脚本。

相关内容