24

I am trying to set up Continuous Integration (CI) in Bitbucket Pipelines for Android.

I have created a sample blank activity using Android Studio 2.1.1.

With Pipelines I'm using the uber/android-build-environment Docker container which creates the environment nicely. Here is my bitbucket-pipelines.yml

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

Some changes are needed since uber/android-build-environment is expecting to be run like so:

docker run -i -v $PWD:/project -t uber/android-build-environment /bin/bash /project/ci/build.sh

For example, the source is not copied to the volume /project but instead Pipelines copies the contents of the Bitbucket repo to the working directory of the container at:

/opt/atlassian/bitbucketci/agent/build

And when ./gradlew assembleDebug is run I get the following error:

...

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type TaskArtifactStateCacheAccess using TaskExecutionServices.createCacheAccess().
> 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

Running ls -al in the working directory gives:

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
Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
Ryan R
  • 8,342
  • 15
  • 84
  • 111
  • I did not find other alternative than using the `uber/android-build-environment:latest` Docker image to build and Android Gradle-based projet using Bitbucket Pipelines. Are there any other ways to do it ? Did you solve your issue ? – metch Jul 15 '16 at 06:21
  • Unfortunately not yet. This seems to be an issue with Pipelines not the build container. – Ryan R Jul 15 '16 at 06:22
  • @RyanR I new to CI integration having trouble with android development setup so if possible can you help me out in with setting CI with Bitbucket pipelines – twister_void Sep 30 '16 at 12:28
  • @RyanR Join this room to talk more http://chat.stackexchange.com/rooms/46117/ci-intergeation-with-docker – twister_void Sep 30 '16 at 12:49
  • can anybody explain what are the process happens while bitbucket-pipelines started running? uber/android-build-environment Docker container will be downloaded to our local machine ? – LOG_TAG Oct 15 '16 at 18:58
  • 1
    @LOG_TAG When you push changes to your Bitbucket project (with a bitbucket-pipelines.yml file present) then the Docker image specified in your bitbucket-pipelines.yml (in this question they were using uber/android-build-environment Docker) will be downloaded and run on Bitbucket Pipelines (on their build servers, not your local machine). This answer might help make it more clear: http://stackoverflow.com/a/40055055/196486 – Travis Oct 16 '16 at 08:08

3 Answers3

11

It's a bug in their system , I report it(issue url, it's quite long) to them and they have fixed it (fix url).I have tested on my project and it successfully build.Try to build your project now and good luck.

Geng Jiawen
  • 8,904
  • 3
  • 48
  • 37
  • Thanks, yes the project now builds successfully. – Ryan R Jul 25 '16 at 17:14
  • why I'm getting _+ ./gradlew assembleDebug bash: ./gradlew: No such file or directory_ – LOG_TAG Oct 15 '16 at 19:03
  • @RyanR can you share the working bitbucket-pipelines.yml file? and where I have to put _docker run -i -v $PWD:/project......._ ? in the yml file only I have to put this! Any info will be grateful. – LOG_TAG Oct 15 '16 at 19:19
  • 2
    The `bitbucket-pipelines.yml` in the question should be fine now. – Ryan R Oct 15 '16 at 20:09
1

It looks like uber/android-build-environment is not supported anymore.

I ended up using javiersantos/android-ci instead which works perfectly from scratch.

Just add the following content to bitbucket-pipeline.yml:

image: javiersantos/android-ci:27.0.3

pipelines:
  default:
    - step:
        script:
          - export GRADLE_USER_HOME=`pwd`/.gradle
          - chmod +x ./gradlew
          - ./gradlew assembleDebug
Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
  • https://hub.docker.com/r/uber/android-build-environment/ page still exists. – Ryan R Sep 04 '18 at 17:11
  • @RyanR it exists, but it is outdated (last update happened 2 yers ago). One can't build SDK 27 based project using their image. – Sasha Shpota Sep 04 '18 at 18:40
  • As of June 2019, Uber's Docker image for Android is [unmaintained and unsupported](https://github.com/uber-archive/android-build-environment). There are other Docker images to use, like [MingChen](https://github.com/mingchen/docker-android-build-box) and [danylovolokh](https://github.com/danylovolokh/Setup-Free-Bitbucket-Cloud-CI). More info here: https://stackoverflow.com/questions/39806261/android-environment-using-docker-and-bitbucket-pipelines – Mr-IDE Jun 29 '19 at 16:25
  • I recommend to use the androidsdk/android-30 image. More details here: https://1gravityllc.medium.com/ci-cd-for-android-using-bitbucket-pipelines-and-gradle-play-publisher-f00d6047ecb5 – Emanuel Moecklin Mar 30 '21 at 17:55
0

Could you symlink your project from /opt/atlassian/bitbucketci/agent/build to /project from within the container? ln -s /opt/atlassian/bitbucketci/agent/build /project is the command you'll need.

or alternatively copy the files to the new path?

I have no experience with android development, so YMMV :)