解压后直接运行 sdkmanager 各种报错:
$ ./sdkmanager --update
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)
解决
- 设置首选ANDROID_HOME
- 将commandlinetools zip文件下载并解压缩到名为的目录中cmdline-tools,该目录位于内部ANDROID_HOME
- 将目录追加$ANDROID_HOME/cmdline-tools/tools/bin到环境变量PATH,以便系统知道在哪里查找sdkmanager
$ mkdir -p ~/Library/Android/cmdline-tools
$ mv tools ~/Library/Android/cmdline-tools/ # 把解压出来的 tools 移到 cmdline-tools 下面
$ ANDROID_HOME=~/Library/Android
$ ~/Library/Android/cmdline-tools/tools/bin/sdkmanager --version
4.0.1
然后打开 .bash_profile 设置 ANDROID_HOME 和 PATH
export ANDROID_HOME=~/Library/Android
export PATH=\(PATH:\)ANDROID_HOME/cmdline-tools/tools/bin
然后
$ source ~/.bash_profile
$ sdkmanager --version
4.0.1
$
done!