Installing android build tools 23.0.2

TL;DR Add this to your circle.yml:

dependencies:
  pre:
    - echo y | android update sdk --no-ui --all --filter "tools"
    - echo y | android update sdk --no-ui --all --filter "build-tools-23.0.2"

Attempting to install build-tools-23.0.2 using the echo y | android update sdk --no-ui --all --filter "build-tools-23.0.2" command will result in the following error message:

Error: Ignoring unknown package filter 'build-tools-23.0.2'
Warning: The package filter removed all packages. There is nothing to install.
         Please consider trying to update again without a package filter.

You can work around this by running this command first:

echo y | android update sdk --no-ui --all --filter "tools"
4 Likes

This works but it adds a minute or so to every build.

Is there a way to do it so that the results are cached? Or can the container simply be updated with the latest tools so we don’t need to do this at all?

3 Likes

Build Tools 23.0.2 have been out since November 2015. Any chance those can be pre-installed?
https://circleci.com/docs/1.0/android/

2 Likes

BTW, this adds more than 2 minutes to our builds, which total more than 9 minutes. That’s more than 20% of the run time!

1 Like

@frank Is there any way to cache this update? It’s adding 4 minutes onto our builds every time. And/Or is there any timeline for adding build tools 23.0.2 to the preinstalled packages? It’s been out for several months now

this adds roughly 21 seconds to the build not 1-2 mins… or even 4 like some people are saying…

if you are redownloading the build tools each build you DO NOT have circleci configured properly.

the dependencies are supposed to be cached. My build runs a step called restore cache for 17 seconds, but after that 17 seconds the same script that usually takes over 1 minute to download dependencies just does a filesystem check that the cache has not been invalidated and is present and continues on, takes 9 seconds. My Build command that used to take 2:50 + to download gradle and build the apk is about 1 minute quicker as it no longer needs to download gradle.

this isnt exactly what im using but it gives you the jist…
in a bash script

BTOOLS=/usr/local/android-sdk-linux/build-tools/23.0.2

if [ ! -e BTOOLS]
echo "Cache invalidated updating sdk"
echo y | android update sdk -u -a -t "tool"
echo y | android update sdk -u -a -t "build-tools-23.0.2"
fi
echo “Cache restore complete, sdk updated”

you either see it say invalidated then download everything and then say cache restore complete or after 1 successful build with dependency download + save and after that it will only say echo cache restored sdk updated and take SECONDS to get there…

you also need to add
dependencies:
cache-directories:
- "/usr/local/android-sdk-linux/build-tools
- “/usr/local/android-sdk-linux/extras”
- “~/repoName/.gradle”

in your YAML so that circleci knows to save the files you updated the sdk with for the next container you are given.

circleci’s support… and documentation is TERRIBLE.

1 Like

Leveraging gundal’s answer, here’s what I now have. No additional script is required.

dependencies:
  pre:
    - if ! $(grep -q "Revision=24.4.1" $ANDROID_HOME/tools/source.properties); then echo y | android update sdk -u -a -t "tools"; fi
    - if [ ! -e $ANDROID_HOME/build-tools/23.0.2 ]; then echo y | android update sdk -u -a -t "build-tools-23.0.2"; fi
  cache_directories:
    - /usr/local/android-sdk-linux/tools
    - /usr/local/android-sdk-linux/build-tools/23.0.2

Overall saving me about 30 seconds per build.

2 Likes

Thanks, your tip worked for me.

Why is the build-tools-23.0.2 installation required when the docs indicate that it’s already preinstalled?

Actually, it’s probably not required now that circle has added support for 23.0.2. Yay!

But Google has already moved to 23.0.3. The instructions above can be modified to work for that version (and whatever future versions Circle hasn’t supported yet).

I think it is actually required because my build failed without adding the config you suggested. Either I’m doing it wrong, or the documentation doesn’t actually reflect the current status.

1 Like

That’s impossible. As we developers know, documentation always matches the code.

The workaround in this topic is no longer needed. The Ubuntu 14.04 image has been updated to include the newer Android SDK. PR pending: https://github.com/circleci/circleci-docs/pull/152