7

This is related to "Uninstall old Android SDK versions", except I'd want to do it on a headless Linux CI server (short on disk space).

Does the android command line tool provide options for removing older parts of the SDK? With a quick look, the only things it can delete are AVDs. Did I overlook something?

Alternatively, I guess I could just manually delete stuff from under SDK_HOME. But what things are safe to delete? Other candidates than these?

  • I only need to support API level 14 and up, so I suppose I can delete stuff under platforms/ like android-3 and android-4.
  • docs (800MB), samples (300MB)
  • How about system-images? Do I need e.g. android-18/armeabi-v7a/ and android-18/x86/ if I only want to do automated APK builds (no emulator stuff) using Gradle (and Ant)?

At least upon deleting docs completely, the next time I ran android update sdk --no-ui, it started fetching them again:

   Downloading Documentation for Android SDK, API 19, revision 1

Can I avoid update adding back parts of the SDK that I threw away?

Disclaimer: yes, disk is cheap and really I should just add more. But right now on this particular server (8.5G disk) I don't have that option, yet I'd still like to get it to run Android 19 builds...

Community
  • 1
  • 1
Jonik
  • 80,077
  • 70
  • 264
  • 372

3 Answers3

4

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

TinyTimZamboni
  • 5,275
  • 3
  • 28
  • 24
3

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.

Community
  • 1
  • 1
Josh A.
  • 31
  • 3
2

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.

Community
  • 1
  • 1
CJBS
  • 15,147
  • 6
  • 86
  • 135