部署环境:在甲骨文白嫖的4核24G运行内存arm64的机器

环境准备阶段

首先用docker安装了一个 Jenkins,这个倒是问题不大。在 /etc/jenkins 目录下创建一个 docker-compose.yml 文件。

1
2
3
4
5
6
7
8
9
10
11
version: '3.8'
services:
jenkins:
image: jenkins/jenkins:lts-jdk17
container_name: jenkins
ports:
- "9001:8080" # Jenkins web interface
volumes:
- /etc/jekins/home:/var/jenkins_home
# environment:
# - JAVA_OPTS=-Djenkins.install.runSetupWizard=false # 禁用初始安装向导

第一个进去后安装推荐的插件,然后配置环境变量。
1、”Manage Jenkins” -> Tool,选择 JDK 安装, 把下载好并解压的 JDK 放到 /etc/jekins/home/tools 目录下 下载链接
2、选择 Gradle 安装,把下载好的 Gradle 包放到 /etc/jekins/home/tools 目录下。[下载链接](wget https://services.gradle.org/distributions/gradle-7.5-bin.zip)。
3、去谷歌的网站下载命令行工具放到 /etc/jekins/home/tools 目录下。选择 “Manage Jenkins” -> Tool -> 环境变量。 添加 ANDROID_HOME ,填入 /var/jenkins_home/tools/androidSdk 。

遇到问题

环境准备好后去 Dashboard -> 新建Item。填入任务名称,选择FreeStle project, 点击确认。然后填入 git 仓库地址,设置好git访问凭证。然后去在 Build Step 中选择 Invoke Gradle script。Gradle version 选择之前配置好的 app:assembleRelease –no-daemon 。然后坑就这样出现了。控制台报错:

1
2
3
4
5
6
7
8
9
AAPT2 aapt2-7.4.0-8841542-linux Daemon #0: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 1: ELF: not found
AAPT2 aapt2-7.4.0-8841542-linux Daemon #1: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 1: ELF: not found
AAPT2 aapt2-7.4.0-8841542-linux Daemon #1: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 2: P�: not found
AAPT2 aapt2-7.4.0-8841542-linux Daemon #1: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 3: Syntax error: "(" unexpected
AAPT2 aapt2-7.4.0-8841542-linux Daemon #0: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 2: P�: not found
AAPT2 aapt2-7.4.0-8841542-linux Daemon #0: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 3: Syntax error: "(" unexpected
AAPT2 aapt2-7.4.0-8841542-linux Daemon #2: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 1: ELF: not found
AAPT2 aapt2-7.4.0-8841542-linux Daemon #2: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 2: P�: not found
AAPT2 aapt2-7.4.0-8841542-linux Daemon #2: Unexpected error output: /var/jenkins_home/.gradle/caches/transforms-3/c1237721b022c496551fdc9f0302830d/transformed/aapt2-7.4.0-8841542-linux/aapt2: 3: Syntax error: "(" unexpected

然后去 Google 一搜,才发现这个是 Google 埋下的坑。然后在 issueTracker 中找到了这个三方编译的支持 arm64 的 aapt2 工具,下载好之后在 ChatGPT的帮助下将打包指令修改为 app:assembleRelease –no-daemon -Pandroid.aapt2FromMavenOverride=/path/to/aapt2 。