Github Action是一个强大的CI/CD工具,支持与Gradle Managed Device的集成,来实现在GitHub上自动化构建和测试Android应用程序的流程。下面给出如何在Github Action中使用Gradle Managed Device的代码示例。
在.github/workflows/build.yml文件中添加如下代码:
name: Android CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Gradle Build with Managed Device
uses: Gradle-Managed-Device/action-gradle-managed-device@main
with:
gradle-version: '7.2'
serial: ${{ secrets.MANAGED_DEVICE_SERIAL }}
log-level: 'debug'
task: 'build'
其中,
将此代码添加到.build.gradle文件的repositories块中:
maven {
url 'https://jitpack.io'
}
这可以让Gradle在JitPack上寻找Gradle Managed Device Action。最后,执行“./gradlew build”命令,即可将Gradle Managed Device集成到Github Action中。