简体   繁体   English

使用Gitlab CI生成Android构建

[英]Generating Android build with Gitlab CI

I just installed Gitlab as repository for my projects and I want to take advantages of their Gitlab CI system. 我刚刚安装了Gitlab作为我的项目的存储库,我想利用他们的Gitlab CI系统。 I want to automatically generate a distribution and debug Apk after each commit. 我希望在每次提交后自动生成分发并调试Apk。 I googled but I didn't find anything as a tutorial or similar cases. 我用Google搜索,但我没有找到任何教程或类似案例。 If someone could guide me in some way, it would be great. 如果有人能以某种方式指导我,那就太好了。

Thanks! 谢谢!

I've just written a blog post on how to setup Android builds in Gitlab CI using shared runners . 我刚刚写了一篇关于如何使用共享运行器在Gitlab CI中设置Android构建的博客文章。

The quickest way would be to have a .gitlab-ci.yml with the following contents: 最快的方法是使用.gitlab-ci.yml其中包含以下内容:

image: openjdk:8-jdk

variables:
  ANDROID_TARGET_SDK: "24"
  ANDROID_BUILD_TOOLS: "24.0.0"
  ANDROID_SDK_TOOLS: "24.4.1"

before_script:
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
  - wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz
  - tar --extract --gzip --file=android-sdk.tgz
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_TARGET_SDK}
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS}
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services
  - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - chmod +x ./gradlew

build:
  script:
    - ./gradlew assembleDebug
  artifacts:
    paths:
    - app/build/outputs/

This starts off using the Java 8 Docker image, then proceeds to download and install the necessary bits of the Android SDK before your build runs. 这将从使用Java 8 Docker映像开始,然后在构建运行之前继续下载并安装必要的Android SDK。 My post also goes into detail as to how you can build this into a Docker image and host it on Gitlab itself. 我的帖子还详细介绍了如何将其构建为Docker镜像并将其托管在Gitlab本身上。

Hopefully that helps! 希望这有帮助!

UPDATE - 4/10/2017 更新 - 4/10/2017

I wrote the canonical blog post for setting up Android builds in Gitlab CI back in November '16 for the official Gitlab blog. 我在16年11月为官方Gitlab博客写了关于在Gitlab CI中设置Android版本的规范博客文章。 Includes details on how to run tests and such as well. 包括有关如何运行测试等的详细信息。 Linking here. 链接在这里。

https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/ https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/

You can add a build step to your GitLab CI project as below. 您可以向GitLab CI项目添加构建步骤,如下所示。

gradle assemble

在此输入图像描述

This will generate debug and release APK's of the commit pushed at: 这将生成调试并发布提交的APK的提交:

/build/outputs/apk/

You could then write a script to archive the generated APK's however you require. 然后,您可以编写脚本来存档生成的APK,但是您需要。

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

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