title: Android CI using Bitbucket Pipelines and Docker
body: <p>I am trying to set up Continuous Integration (CI) in <a href="https://bitbucket.org/product/features/pipelines">Bitbucket Pipelines</a> for Android. </p>
  
  <p>I have created a sample blank activity using Android Studio 2.1.1.</p>
  
  <p>With Pipelines I'm using the <a href="https://hub.docker.com/r/uber/android-build-environment/">uber/android-build-environment</a> Docker container which creates the environment nicely. Here is my <code>bitbucket-pipelines.yml</code></p>
  
  <pre><code>image: uber/android-build-environment:latest
  
  pipelines:
    default:
      - step:
          script:
            - echo y | android update sdk --filter "extra-android-m2repository" --no-ui -a # Grab the Android Support Repo which isn't included in the container
            - ./gradlew assembleDebug
  </code></pre>
  
  <p>Some changes are needed since <a href="https://hub.docker.com/r/uber/android-build-environment/">uber/android-build-environment</a> is expecting to be run like so:</p>
  
  <pre><code>docker run -i -v $PWD:/project -t uber/android-build-environment /bin/bash /project/ci/build.sh
  </code></pre>
  
  <p>For example, the source is not copied to the volume <code>/project</code> but instead Pipelines copies the contents of the Bitbucket repo to the working directory of the container at: </p>
  
  <pre><code>/opt/atlassian/bitbucketci/agent/build
  </code></pre>
  
  <p>And when <code>./gradlew assembleDebug</code> is run I get the following error:</p>
  
  <pre><code>...
  
  FAILURE: Build failed with an exception.
  
  * What went wrong:
  Could not create service of type TaskArtifactStateCacheAccess using TaskExecutionServices.createCacheAccess().
  &gt; Failed to create parent directory '/opt/atlassian/bitbucketci/agent/build/.gradle' when creating directory '/opt/atlassian/bitbucketci/agent/build/.gradle/2.10/taskArtifacts'
  
  * Try:
  Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  
  BUILD FAILED
  
  Total time: 56.449 secs
  </code></pre>
  
  <p>Running <code>ls -al</code> in the working directory gives:</p>
  
  <pre><code>ls -al
  total 52
  drwxr-xr-x 5 root root 4096 May 31 22:33 .
  drwxr-xr-x 3 root root 4096 May 31 22:43 ..
  drwxr-xr-x 3 root root 4096 May 31 22:33 app
  -rw-r--r-- 1 root root  462 May 31 22:33 bitbucket-pipelines.yml
  -rw-r--r-- 1 root root  498 May 31 22:33 build.gradle
  drwxr-xr-x 8 root root 4096 May 31 22:33 .git
  -rw-r--r-- 1 root root  387 May 31 22:33 .gitignore
  drwxr-xr-x 3 root root 4096 May 31 22:33 gradle
  -rw-r--r-- 1 root root  855 May 31 22:33 gradle.properties
  -rwxr-xr-x 1 root root 4971 May 31 22:33 gradlew
  -rw-r--r-- 1 root root 2314 May 31 22:33 gradlew.bat
  -rw-r--r-- 1 root root   15 May 31 22:33 settings.gradle
  </code></pre>