travis-ci / packer-templates

Templates for Packer!
MIT License
105 stars 54 forks source link

Android Trusty (ci-cookiecat) fixes - `avdmanager` does not come preinstalled #482

Open Lyoness opened 7 years ago

Lyoness commented 7 years ago

https://github.com/travis-pro/team-sapphire/issues/667#issuecomment-321265220

After some tests (similar to the ones I did to debug the previous sdkmanager issue here) it seems that avdmanager is nowhere in the VM, so it seems that avdmanager does not come installed and this is not a PATH issue as it happened with sdkmanager previously.

If I understand this correctly, avdmanager replaces the android avd command as sdkmanager replaces android sdk one.

Looks like avdmanager comes in the SDK tools file for Linux that Google distributes: https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip

iriberri commented 7 years ago

Since the release of Trusty as default distribution there are a lot of people starting to work with the new Cookiecat image, and avdmanager is required for all the previous android avd commands after the android tool was

meatballhat commented 7 years ago

@iriberri Is there a workaround available to install this at build time? I definitely want to get this addressed in the image itself, but wanted to get clarification on how much of a blocker this is.

BanzaiMan commented 7 years ago

A run-time workaround is available, sort of, but will have some major involvement from the users.

Shoehorning our current Android component installation method

I tried some stuff (https://github.com/uber/AutoDispose/pull/79#issuecomment-327919024) without much tweaking:

I am not quite sure what is happening here. In https://travis-ci.org/uber/AutoDispose/builds/272986414#L1139-L1144, you can see that build-tools 26.0.1 is installed (by android update sdk, which may or may not make a difference). According to https://developer.android.com/studio/command-line/avdmanager.html, one should expect this in android_sdk/tools/bin/, but it is not clear to me where this is. Our default installation exists in /usr/local/android-sdk (which is a symlink to /usr/local/android-sdk-25.2.3), but after the installation avdmanager does not exist in /usr/local/android-sdk/tools/bin.

My understanding is that avdmanager is included for SDK tools 25.3.0 and later, but installing a version satisfying this condition does not seem to make it available. (I ran a debug build to poke around.)

Enter sdkmanager

Using sdkmanager (instead of android) appears to work, though. https://github.com/travis-ci/travis-build/tree/ha-android-sdkmanager

It installs packages into /opt/android, which is then added to $PATH. You can see avdmanager is available. (It is not clear to me how this translates to actual builds, since I have zero experience with Android development.)

It is conceivable that these steps are adaptable without changing travis-build.

  1. Create a new Android SDK Root. (Currently it is /usr/local/android-sdk(*), but maybe this is not usable. /opt is writable; in the above example I used /opt/android.)
  2. Use sdkmanager currently available on $PATH to install packages with --sdk_root=/opt/android.
  3. Finally, prepend /opt/android/tools/bin to $PATH.

Long-term goal

We should eventually move to sdkmanager (https://github.com/travis-ci/travis-ci/issues/8155#issuecomment-318255019) but I feel this would need more testing.