首页 > 解决方案 > GItlab CI :- 如何使用 Gitlab-CI 在 Android 中创建多个 apk(如开发、登台和生产)?

问题描述

我可以debug.apk通过以下方法在 Gitlab 中创建单个构建(apk),就像使用 Gitlab-CI 一样。

在我的里面.gitlab-ci.yml,我已经完成了这个条目。请检查一次,

image: jangrewe/gitlab-ci-android

stages:
  - build

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - chmod +x ./gradlew

cache:
  key: ${CI_PROJECT_ID}
  paths:
    - .gradle/

build:
  stage: build
  tags:
    - dev-ci
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
      - app/build/outputs/

我已经创建了docker图像并在 Gitlab 上的每次推送中获得了构建(apk)。

我的问题是,我们可以设置不同的阶段,比如DevelopmentStagingProduction指出不同BASE_URL的应用程序。我也在文档中搜索过,但没有得到解决方案。请帮助我。谢谢

标签: androidgitlabapkgitlab-cigitlab-ci-runner

解决方案


要么设置BASE_URL.gitlab-ci.yml

image: jangrewe/gitlab-ci-android

stages:
  - build

before_script:
  - export GRADLE_USER_HOME=$(pwd)/.gradle
  - chmod +x ./gradlew

cache:
  key: ${CI_PROJECT_ID}
  paths:
    - .gradle/

development:
  stage: build
  tags:
    - dev-ci
  script:
    - ./gradlew assembleDevelopment
  artifacts:
    paths:
      - app/build/outputs/
  variables:
    BASE_URL: "https://stackoverflow.com"

staging:
  stage: build
  tags:
    - dev-ci
  script:
    - ./gradlew assembleStaging
  artifacts:
    paths:
      - app/build/outputs/
  variables:
    BASE_URL: "https://yahoo.com"

production:
  stage: build
  tags:
    - dev-ci
  script:
    - ./gradlew assembleProduction
  artifacts:
    paths:
      - app/build/outputs/
  variables:
    BASE_URL: "https://google.com"

您必须在您的 gradle 文件中创建 Android Flavors development, staging,并让它们使用环境变量。productionBASE_URL

或者,就像Alexander Hoffmann建议的那样,在您的 gradle 文件中执行所有这些操作,而不在.gitlab-ci.yml.


推荐阅读