会讲这个题目其实有点微妙,但是都讲完了测试,却不讲 CI 我觉得好像少了一点什麽。
不知道 Android App 工程师,到底要不要自己维护 CI呢?我觉得需要。
所以我就写了一篇自己简单搞定自己的 CI 的文章。
不过维护 CI 之前要先学会基础的 Git 使用,
Git 教学这方面的文网路上也有许多很好的学习资源,
如下:
假设你已经学习会了 Git,那我们怎麽样一天内搞定 CI呢?
我自己有接触过 Gitalb, Bitbucket, Github,其实大多数的 CI 都差不多,
我自己觉得 Gitlab 是最熟悉的所以我就讲 Gitlab,其他的有机会再介绍罗~
然後因为我同时也在 GDG Taipei 社群服务,稍微推广一下 GCP 的服务,哈哈!
因为真的很好用啊!不信等等看,那就开始讲解罗~
首先我们将一个本地确定可以执行通过的专案,上传到Gitlab上,如下图:
然後点画面上的 new file
选择 .gitlab-ci.yml 的 Android
就会出现Gitlab 预设的 Android CI yaml setting了,通常来说这个 settting 就可以执行完 CI !
可以点到 CI/CD 这个页面,就能看到CI正在执行了!
执行好後的画面如下!
怎麽没成功QQ
没关系,我们先回头来看 究竟 gitlab-CI的 yaml档里面是讲些什麽~
image: openjdk:8-jdk
variables:
#(ANDROID COMPILE SDK版本号码)
ANDROID_COMPILE_SDK: "29"
#(ANDROID BUILD TOOLS版本号码)
ANDROID_BUILD_TOOLS: "29.0.3"
#(SDK 版号)
#ANDROID_SDK_TOOLS: "6514223"
# Packages installation before running script
before_script:
- apt-get --quiet update --yes
- apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1
# Setup path as android_home for moving/exporting the downloaded sdk into it
- export ANDROID_HOME="${PWD}/android-home"
# Create a new directory at specified location
- install -d $ANDROID_HOME
# Here we are installing androidSDK tools from official source,
# (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well)
# after that unzipping those tools and
# then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build
- wget --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
# move to the archive at ANDROID_HOME
- pushd $ANDROID_HOME
- unzip -d cmdline-tools cmdline-tools.zip
- popd
- export PATH=$PATH:${ANDROID_HOME}/cmdline-tools/tools/bin/
# Nothing fancy here, just checking sdkManager version
- sdkmanager --version
# use yes to accept all licenses
- yes | sdkmanager --sdk_root=${ANDROID_HOME} --licenses || true
- sdkmanager --sdk_root=${ANDROID_HOME} "platforms;android-${ANDROID_COMPILE_SDK}"
- sdkmanager --sdk_root=${ANDROID_HOME} "platform-tools"
- sdkmanager --sdk_root=${ANDROID_HOME} "build-tools;${ANDROID_BUILD_TOOLS}"
# Not necessary, but just for surity
- chmod +x ./gradlew
#上面这一段都是在描述如何在Git runner 下载指定的 Android SDK 跟对应的 compile 工具
# 执行 Check Linting
# Basic android and gradle stuff
# Check linting
lintDebug:
interruptible: true
stage: build
script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint
# Compile Android APK
# Make Project
assembleDebug:
interruptible: true
stage: build
script:
- ./gradlew assembleDebug
artifacts: // 执行完後将这个资料夹的档案上传至Gitlab
paths:
- app/build/outputs/
## 执行 android test
# Run all tests, if any fails, interrupt the pipeline(fail it)
debugTests:
interruptible: true
stage: test
script:
- ./gradlew -Pci --console=plain :app:testDebug
看完以後,再点进去这里面看一下为什麽执行失败。
原来是现在 Android project 的要求 Java 要用11以上了~,那就改一下吧!
点击 File 打开.gitlab-ci.yaml档
将8-jdk改成11-jdk,然後就等他再次执行
登愣!完成。
如果今天这个也会了,那我们就明天见罗:)
值得一提的是目前Gitlab 的免费额度是一个月可以执行 400分钟,
有超过这个需求的话,就要自行安装Git-runner或是购买!
https://about.gitlab.com/pricing/
本文同步发表在 Medium 上:文章连结
>>: [Day28] React - 建立React 元件 (Component )
webhook 究竟是什麽呢? 我认为在了解Webhook前我们需要先了解Hook(钩子编程) Ho...
简介厨房:Shioaji Shioaji是永丰证开发出来的Python API,用来给客户自行开发自...
今天来介绍一下 solidity 里面一个很特殊的东西 events。 我们介绍了这几天,都还没有看...
我相今天的篇章是大家期待已久的,因为经过前面十天的努力,今天终於要将我们的部落格公开在世人面前啦!不...
我自己是从RD出身的主管,我自己也想了很久,我到底做对了什麽,与可能做错了什麽,让我自己培养出这样的...