Android CI #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Android CI | |
on: | |
workflow_dispatch: | |
inputs: | |
docker_images: | |
description: '请填写docker镜像名称 多个用英文逗号分开' | |
required: true | |
default: 'alpine:latest' # 设置默认的 Docker 镜像列表 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: gradle | |
- name: Install Android SDK & Build Tools | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y wget unzip | |
wget https://dl.google.com/android/repository/commandlinetools-linux-7583922_latest.zip | |
unzip commandlinetools-linux-7583922_latest.zip -d cmdline-tools | |
sudo mv cmdline-tools /usr/local/android-sdk | |
echo "export ANDROID_SDK_ROOT=/usr/local/android-sdk" >> $GITHUB_ENV | |
echo "export PATH=\$PATH:/usr/local/android-sdk/cmdline-tools/bin" >> $GITHUB_ENV | |
# Accept licenses | |
yes | sdkmanager --licenses | |
# Install build tools (includes zipalign) | |
sdkmanager "build-tools;30.0.3" | |
# Add build tools path to environment | |
echo "export PATH=\$PATH:/usr/local/android-sdk/build-tools/30.0.3" >> $GITHUB_ENV | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew assembleRelease | |
# Step 6: Generate Keystore using keytool | |
- name: Generate Keystore | |
run: | | |
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize 2048 -validity 10000 \ | |
-alias my-key-alias -storepass android -keypass android \ | |
-dname "CN=Example, OU=Dev, O=MyCompany, L=City, ST=State, C=US" | |
# Step 7: Sign APK | |
- name: Sign APK | |
run: | | |
jarsigner -verbose -keystore my-release-key.jks -storepass android -keypass android \ | |
app/build/outputs/apk/release/app-arm64-v8a-release-unsigned.apk my-key-alias | |
zipalign -v 4 app/build/outputs/apk/release/app-arm64-v8a-release-unsigned.apk app/build/outputs/apk/release/app-release.apk | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: build-artifact | |
path: app/build/outputs/apk/release/app-release.apk |