11

I am trying to make a docker image that I can use to build Android projects, using Shippable.

The problem is the android update sdk command, which gives the following error:

Installing Android SDK Tools, revision 24.2
  Failed to rename directory /opt/android-sdk-linux/tools to /opt/android-sdk-linux/temp/ToolPackage.old01.
  Failed to create directory /opt/android-sdk-linux/tools

I found somewhat of a solution here: https://stackoverflow.com/a/8839359/867099 but it's for Windows, and does not seem to fix the problem on linux. It appears that during the update command, the current directory is in use and therefore cannot be renamed.

My workaround sofar, using that workaroundsuggestion, is this:

RUN cp -r /opt/android-sdk-linux/tools /opt/android-sdk-linux/tools_copy

RUN cd /opt/android-sdk-linux/tools && echo 'y' | /opt/android-sdk-linux/tools_copy/android update sdk --no-ui -a --filter tools,platform-tools,build-tools-22.0.1,android-21,extra-android-support,extra-google-google_play_services --force

In order to automatically accept the license, I echo 'y' to the android command.

But I think the android command should also run in the correct directory, which is why I cd into it first.

But, it still fails. I'm rather stumped on how to fix this issue, so any help is appreciated.

------ UPDATE --------

I run the android sdk update command without the tools filter, and in the end, my gradle builds are successful. So I don't know for sure whether it's a problem to not update them...

Community
  • 1
  • 1
xorgate
  • 2,244
  • 1
  • 24
  • 36
  • 1
    "It appears that during the update command, the current directory is in use and therefore cannot be renamed" -- try `adb kill-server` before running your `android update sdk` command. Or see if there are any other running processes that might reference this directory. – CommonsWare May 18 '15 at 10:52
  • I think it's indeed ````adb```` that's accessing the dir, but it is started when I run the update command. So it does not seem to be possible to kill it in time. – xorgate May 18 '15 at 12:11
  • May be related to storage driver according to this https://github.com/travis-ci/travis-ci/issues/2848 – shbi Jun 04 '16 at 04:11
  • I don't think you need to change directory to the `tools/` folder before running the `android update sdk` command in the `tools_copy/` folder – Jianxin Gao Sep 12 '16 at 21:44

2 Answers2

10

This can be solved by combining all Android SDK commands in a single Dockerfile's RUN command. It has something to do with Docker's file system.

For a detailed explanation from a post on Issue Tracker for the Android Open Source Project:

The problem is caused when you run the SDK update in a Docker container. Docker uses a special filesystem which works like a version control system (e.g. git) and records all changes made to the filesystem. The problem is that the SDK update uses a hardlink move operation to move the 'tools' directory, which is not supported by the underlying Docker filesystem.

The solution for this is to simply run all Android SDK commands in a single 'RUN' command in Docker. That way, the hardlink move works as normal, as long as you don't use the 'hardlink move' operation between multiple RUN command (snapshots). The advantage of this is also that your Docker layers will be smaller (compared to running multiple seperate RUN commands).

Here is the line from the Dockerfile:

RUN wget https://dl.google.com/android/android-sdk_r24.4.1-linux.tgz && \
    tar xzf android-sdk_r24.4.1-linux.tgz && \
    rm android-sdk_r24.4.1-linux.tgz && \
    (echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter platform-tools,tools -a ) && \
    (echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter extra-android-m2repository,extra-android-support,extra-google-google_play_services,extra-google-m2repository -a) && \
    (echo y | android-sdk-linux/tools/android -s update sdk --no-ui --filter build-tools-23.0.2,android-24 -a)
atlas
  • 168
  • 1
  • 7
  • Why **build-tools-23.0.2**, and not **25.0.0**? – IgorGanapolsky Nov 14 '16 at 22:17
  • 1
    @IgorGanapolsky 25.0.0 was not available at that time. https://developer.android.com/studio/releases/build-tools.html – Jianxin Gao Dec 04 '16 at 10:23
  • Well, I wouldn't say that it has nothing to do with Docker if "the SDK update uses a hardlink move operation to move the 'tools' directory, which is not supported by the underlying Docker filesystem." – Petrus Theron Feb 01 '18 at 17:35
0

This is what's currently working for me, you can see the update command successfully running below. In my environment these are 3 different docker images in one FROM hierarchy so you can likely combine a lot of the apt-gets if that's not your case.

FROM ubuntu:14.04

# Set debconf to run non-interactively
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections

# Install base dependencies
RUN apt-get update && apt-get install -y -q --no-install-recommends \
        apt-transport-https \
        build-essential \
        ca-certificates \
        curl \
        git \
        libssl-dev \
        python \
        rsync \
        software-properties-common \
        wget \
    && rm -rf /var/lib/apt/lists/*

# Install the JDK
RUN echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
    echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections && \
    add-apt-repository -y ppa:webupd8team/java && \
    apt-get update -qq && \
    DEBIAN_FRONTEND=noninteractive apt-get install -qqy --force-yes oracle-java7-installer && \
    rm -rf /var/lib/apt/lists/* /var/cache/oracle-jdk7-installer

# Install Android Dev Tools
RUN apt-get update && apt-get install -y -q --no-install-recommends \
        lib32ncurses5 \
        lib32stdc++6 \
        lib32z1 \
        libswt-gtk-3-java \
        unzip \
    && rm -rf /var/lib/apt/lists/*

RUN wget -qO- "http://dl.google.com/android/android-sdk_r23.0.2-linux.tgz" | tar -zxv -C /opt/

RUN cd /opt/android-sdk-linux/tools/ && \
    echo y | ./android update sdk --all --filter platform-tools,build-tools-20.0.0,android-17,sysimg-17,system-image,extra-android-support --no-ui --force

ENV PATH /opt/android-sdk-linux/build-tools/20.0.0:$PATH
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197