Uninstalling selected parts of Android SDK on the command line

我只是一个虾纸丫 提交于 2019-12-05 06:57:54
Josh A.

Anything except tools/ can be re-installed generally with an

android list sdk -a

and

android update sdk --no-ui -a --filter <#index>

I will often blow away my add-ons/ and build-tools/ folders and reinstall my add-ons/ and build-tools/. If you need to automate accepting the license, another little trick is the following, at least if you're installing them one at a time:

android update sdk --no-ui -a --filter <#index> 0<<EOF
y
EOF

The "android" command itself lives within the "SDK Tools" package or tools/ directory, so you can't remove that, because then you can't install anything else. I also generally wouldn't remove platform-tools/, as then you can't build anything, unless you're installing a new/older version. If you look under <sdk-folder>/SDK Readme.txt, you will see the following in the first paragraph to confirm this:

Welcome to the Android SDK!

The Android SDK archive initially contains only the basic SDK tools. It does not contain an Android platform or any third-party libraries. In fact, it doesn't even have all the tools you need to develop an application.

In order to start developing applications, you must install the Platform-tools and at least one version of the Android platform, using the SDK Manager.

CJBS

It seems that you need to download just the parts that you need. Doing a android update sdk --no-ui without other parameters downloads everything, and thus is time-consuming and wasteful.

The --filter parameter to determine the packages that you need, and using them each time you want to do an update. There's a more detailed explanation on how to do that here (and even more on the android command here).

If periodically changing the components that are needed (e.g. targeting a different platform), you could create a script that deletes the components under the various folders that are not needed (e.g. APIs under android-sdk-linux/platforms) and then re-create with just the components that you want.

The android list sdk -e command will give an extended list of packages that can be used with the --filter parameter, and thus allows installation of just specific components.

After reviewing an excellent answer automated way to use the expect command to automatically accept the license prompts, I ended up with this to install and update the components that I need, without downloading everything else (on Ubuntu):

expect -c '
set timeout -1;
spawn /opt/android-sdk-linux/tools/android update sdk --no-ui --filter tools,build-tools-20.0.0,platform-tools,android-16,extra-android-support,extra-android-m2repository;
expect {
    "Do you accept the license" { exp_send "y\r" ; exp_continue }
    eof
}
'

Note the components tools,build-tools-20.0.0,platform-tools,android-16,extra-android-support,extra-android-m2repository specified with the --filter parameter that restrict the download to just these parts.

Running this script once downloads just those components. Running again determines that nothing needs updating, but does give a confusing set of messages:

Error: Ignoring unknown package filter 'tools'
Error: Ignoring unknown package filter 'build-tools-20.0.0'
Error: Ignoring unknown package filter 'platform-tools'
Error: Ignoring unknown package filter 'android-16'
Error: Ignoring unknown package filter 'extra-android-support'
Error: Ignoring unknown package filter 'extra-android-m2repository'
Warning: The package filter removed all packages. There is nothing to install.
         Please consider trying to update again without a package filter.

These messages just mean that nothing was updated -- components included in the --filter specification aren't actually uninstalled.

From what I've been able to gather, you can just delete directories in /platforms /skins and /system-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!