繁体   English   中英

如何通过 Gitlab CI/CD 和 Docker 构建 Android APK?

How to build Android APK via Gitlab CI/CD and Docker?

提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供   中文繁体   英文版本   中英对照 版本,有任何建议请联系yoyou2525@163.com。

我已经在本地安装了 Gitlab-Runner 并在我的 macOS 上使用shell执行器对其进行了配置。

我有以下 .yaml

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - export ANDROID_HOME=/Users/qfunz/Library/Android/sdk
  - export ANDROID_SDK_ROOT=/Users/qfunz/Library/Android/sdk
  - chmod +x ./gradlew

stages:
  - build

create common folder to store build:
  stage: build
  needs: []
  tags:
    - shell
  script:
    - mkdir popa
  artifacts:
    paths:
      - ./popa


get debug apk build:
  stage: build
  needs: [create common folder to store build]
  tags:
    - shell
  script:
    - ./gradlew app:assembleGooglePlayDebug
    - mv app/build/outputs/apk/googlePlay/debug/*.apk ./popa
  artifacts:
    paths:
      - ./popa

get release apk build:
  stage: build
  needs: [create common folder to store build]
  tags:
    - shell
  script:
    - ./gradlew app:assembleGooglePlayRelease
    - mv app/build/outputs/apk/googlePlay/release/*.apk ./popa
  artifacts:
    paths:
      - ./popa

get release aab build:
  stage: build
  needs: [create common folder to store build]
  tags:
    - shell
  script:
    - ./gradlew app:bundleGooglePlayRelease
    - mv app/build/outputs/bundle/googlePlayRelease/*.aab ./popa
  artifacts:
    paths:
      - ./popa

get one folder build:
  stage: build
  tags:
    - shell
  needs: [get debug apk build, get release apk build, get release aab build]
  script:
    - echo "DONE!!!!!!!!"
  artifacts:
    paths:
      - ./popa

它看起来像这样,效果很好,大约 3 分钟就可以完成

但它是使用我的个人 Android SDK 在我的 macOS 上本地配置的,因此它不能独立。 所以我想把shell executor改成docker

我试过什么?

  1. 我又创建了一个 Gitlab-Runner 并像这样配置它:
concurrent = 10
check_interval = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "docker"
  url = "https://MYURL/"
  token = "MYTOKEN"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    image = "jangrewe/gitlab-ci-android"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache"]
    shm_size = 0
  1. 我已经创建了我的 Dockerfile
FROM jangrewe/gitlab-ci-android

USER root

WORKDIR proj/

COPY . .

ENV SDK_URL="https://dl.google.com/android/repository/commandlinetools-mac-8512546_latest.zip" \
    ANDROID_HOME="/usr/local/android-sdk" 

RUN mkdir "$ANDROID_HOME" .android \
    && cd "$ANDROID_HOME" \
    && mkdir cmdline-tools \
    && cd cmdline-tools \
    && curl -o sdk.zip $SDK_URL \
    && unzip sdk.zip \
    && rm sdk.zip \
    && mv ./cmdline-tools ./latest \
    && mkdir "$ANDROID_HOME/licenses" || true \
    && echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" \
    && cd latest \
    && cd bin \
    && ./sdkmanager --update \
    && yes | ./sdkmanager "build-tools;30.0.3" \
    "platforms;android-30" \
    "platform-tools" 

  1. 我已经用 docker build构建了这个并将它推送到 Gitlab Container Registry,所以我可以像使用图像一样使用它

  2. 我已将 .yaml 更改为

default:                                                  <-----------
  image: pushed_image_from_conteiner_registry             <-----------

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - export ANDROID_HOME=/usr/local/android-sdk            <-----------
  - export ANDROID_SDK_ROOT=/usr/local/android-sdk        <-----------
  - chmod +x ./gradlew

stages:
  - build

create common folder to store build:
  stage: build
  needs: []
  tags:
    - docker                          <-----------
  script:
    - mkdir popa
  artifacts:
    paths:
      - ./popa


get debug apk build:
  stage: build
  needs: [create common folder to store build]
  tags:
    - docker                          <-----------
  script:
    - ./gradlew app:assembleGooglePlayDebug
    - mv app/build/outputs/apk/googlePlay/debug/*.apk ./popa
  artifacts:
    paths:
      - ./popa

get release apk build:
  stage: build
  needs: [create common folder to store build]
  tags:
    - docker                          <-----------
  script:
    - ./gradlew app:assembleGooglePlayRelease
    - mv app/build/outputs/apk/googlePlay/release/*.apk ./popa
  artifacts:
    paths:
      - ./popa

get release aab build:
  stage: build
  needs: [create common folder to store build]
  tags:
    - docker                          <-----------
  script:
    - ./gradlew app:bundleGooglePlayRelease
    - mv app/build/outputs/bundle/googlePlayRelease/*.aab ./popa
  artifacts:
    paths:
      - ./popa

get one folder build:
  stage: build
  tags:
    - docker                          <-----------
  needs: [get debug apk build, get release apk build, get release aab build]
  script:
    - echo "DONE!!!!!!!!"
  artifacts:
    paths:
      - ./popa

(我已经标记了已更改的行)

当我运行我的管道时,2/3 的任务卡在这个阶段:

Welcome to Gradle 7.4.2!
Here are the highlights of this release:
 - Aggregated test and JaCoCo reports
 - Marking additional test source directories as tests in IntelliJ
 - Support for Adoptium JDKs in Java toolchains
For more details see https://docs.gradle.org/7.4.2/release-notes.html
Starting a Gradle Daemon (subsequent builds will be faster)
Configuration on demand is an incubating feature.

我应该在我的shell执行器(效果很好)的代码中更改什么以使用 docker 执行器运行它?

PS给我+10代表所以我可以附上任何你想说明我的问题的图片

问题暂未有回复.您可以查看右边的相关问题.
4 使用 docker 内置 gitlab CI/CD 无法解析名称

我想在 gitlab CI/CD 管道中构建 docker 映像。 我已经使用docker:dind服务配置了docker:latest图像。 在script部分,我调用了docker build... 一切似乎都正常,但是当构建开始时,容器无法解析名称。 在Dockerfile我有一些RUN ap ...

7 使用 Gitlab CI/CD 配置 Docker?

我在 Gitlab CI/CD 中有一个简单的项目设置,使用 Docker 按照本指南在容器上提供站点服务。 但是每当有新作业在推送事件上运行时,我都会收到“容器已在使用中...”错误。 如何在不关闭或杀死容器的情况下将新代码“推送”到我已经运行的网站? ...

10 Gitlab CI/CD 如何

我正在尝试使用 gitlab CI。 我想在我的测试分支更新时发布我的应用程序。 这是我的 gitlab-ci.yml 脚本 我不知道我做错了什么,谢谢你的帮助! ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2022 STACKOOM.COM