Android CI using Bitbucket Pipelines and Docker

☆樱花仙子☆ 提交于 2019-12-20 09:35:40

问题


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

回答1:


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.




回答2:


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 :)




回答3:


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


来源:https://stackoverflow.com/questions/37557551/android-ci-using-bitbucket-pipelines-and-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!