Android Studio更新到2.3之后无法打开SDK Manager

  • 2017-09-28
  • 0
  • 0

今天把Android Studio升级到2.3之后,突然发现无法打开Android SDK下面的SDK Manager和AVD Manager两个文件,因为是更新Android Studio之后才打不开的,所以网上提到的一些设定java路径的方法是无效的,问题出在了更新上面。

SDK Manager本质上是执行tools目录下面的android命令,执行 tools/android 命令发现提示 The "android" command is deprecated.,Google了一下,果然发现Google将原来的SDK Mananger弃用了,官方建议的开启方式是,在Android Studio中打开,见下图:


不过还是习惯原来的SDK Mananger,Google官方也在投票要求进行恢复,在CSDN上看到一篇文章对比了更新前后的tools目录下的变化,作者最后说在官网下载最新的sdk-tools然后覆盖,但是我写这篇文章的时候这样操作是无效的。后来研究了一下,其实只要修改一下tools/android.bat文件的内容即可,首先将现在的tools/android.bat备份一下,然后替换成如下的内容:

  1. @echo off
  2. rem Copyright (C) 2007 The Android Open Source Project
  3. rem
  4. rem Licensed under the Apache License, Version 2.0 (the "License");
  5. rem you may not use this file except in compliance with the License.
  6. rem You may obtain a copy of the License at
  7. rem
  8. rem
  9. rem
  10. rem Unless required by applicable law or agreed to in writing, software
  11. rem distributed under the License is distributed on an "AS IS" BASIS,
  12. rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. rem See the License for the specific language governing permissions and
  14. rem limitations under the License.
  16. rem Useful links:
  17. rem Command-line reference:
  18. rem
  20. rem don't modify the caller's environment
  21. setlocal enableextensions
  23. rem Set up prog to be the path of this script, including following symlinks,
  24. rem and set up progdir to be the fully-qualified pathname of its directory.
  25. set prog=%~f0
  27. rem Grab current directory before we change it
  28. set work_dir=%cd%
  30. rem Change current directory and drive to where the script is, to avoid
  31. rem issues with directories containing whitespaces.
  32. cd /d %~dp0
  35. rem Check we have a valid Java.exe in the path.
  36. set java_exe=
  37. call lib\find_java.bat
  38. if not defined java_exe goto :EOF
  40. set jar_path=lib\sdkmanager.jar;lib\swtmenubar.jar
  42. rem Set SWT.Jar path based on current architecture (x86 or x86_64)
  43. for /f "delims=" %%a in ('"%java_exe%" -jar lib\archquery-26.0.0-dev.jar') do set swt_path=lib\%%a
  45. :MkTempCopy
  46.     rem Copy android.bat and its required libs to a temp dir.
  47.     rem This avoids locking the tool dir in case the user is trying to update it.
  49.     set tmp_dir=%TEMP%\temp-android-tool
  50.     xcopy "%swt_path%" "%tmp_dir%\%swt_path%" /I /E /C /G /R /Y /Q > nul
  51.     copy /B /D /Y lib\common.jar         "%tmp_dir%\lib\"          > nul
  52.     copy /B /D /Y lib\commons-codec*     "%tmp_dir%\lib\"          > nul
  53.     copy /B /D /Y lib\commons-compress*  "%tmp_dir%\lib\"          > nul
  54.     copy /B /D /Y lib\commons-logging*   "%tmp_dir%\lib\"          > nul
  55.     copy /B /D /Y lib\dvlib.jar          "%tmp_dir%\lib\"          > nul
  56.     copy /B /D /Y lib\gson*              "%tmp_dir%\lib\"          > nul
  57.     copy /B /D /Y lib\guava*             "%tmp_dir%\lib\"          > nul
  58.     copy /B /D /Y lib\httpclient*        "%tmp_dir%\lib\"          > nul
  59.     copy /B /D /Y lib\httpcore*          "%tmp_dir%\lib\"          > nul
  60.     copy /B /D /Y lib\httpmime*          "%tmp_dir%\lib\"          > nul
  61.     copy /B /D /Y lib\layoutlib-api.jar  "%tmp_dir%\lib\"          > nul
  62.     copy /B /D /Y lib\org-eclipse-*      "%tmp_dir%\lib\"          > nul
  63.     copy /B /D /Y lib\sdk*               "%tmp_dir%\lib\"          > nul
  64.     copy /B /D /Y lib\swtmenubar.jar     "%tmp_dir%\lib\"          > nul
  66.     rem jar_path and swt_path are relative to PWD so we don't need to adjust them, just change dirs.
  67.     set tools_dir=%cd%
  68.     cd /d "%tmp_dir%"
  70. :EndTempCopy
  72. rem The global ANDROID_SWT always override the SWT.Jar path
  73. if defined ANDROID_SWT set swt_path=%ANDROID_SWT%
  75. if exist "%swt_path%" goto SetPath
  76.     echo ERROR: SWT folder '%swt_path%' does not exist.
  77.     echo Please set ANDROID_SWT to point to the folder containing swt.jar for your platform.
  78.     goto :EOF
  80. :SetPath
  81. rem Finally exec the java program and end here.
  82. REM set REMOTE_DEBUG=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
  83. call "%java_exe% %REMOTE_DEBUG%" "" "" -classpath "%jar_path%;%swt_path%\swt.jar" %*
  85. rem EOF

其实就是原来的android.bat文件的内容,就是将43行里面的 lib\archquery.jar 修改为 lib\archquery-26.0.0-dev.jar 即可。熟悉的界面有回来了:

Mac下可以参考这篇文章:关于mac 里面的 android studio 2.3 里面的 android sdk manager 找不到问题

android studio 更新2.3后,怎么打开sdk manager下载samples?
Standalone SDK Manager option in Android Studio 2.3
android SDK SDK Manager.exe 无法打开,一闪而过最终解决办法
关于mac 里面的 android studio 2.3 里面的 android sdk manager 找不到问题