Update android-ci-cd.yml #10
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/CD | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
name: Build and Publish APK | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout code | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Set up Java 17 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
# Step 3: Set up Android SDK | |
- name: Set up Android SDK | |
uses: android-actions/setup-android@v2 | |
with: | |
api-level: 34 | |
build-tools: 34.0.0 | |
# Step 4: Grant execute permission for Gradle wrapper | |
- name: Grant execute permission for Gradle wrapper | |
run: chmod +x ./gradlew | |
# Create the directory to store the keystore | |
- name: Create keystore directory | |
run: mkdir -p keystore | |
# Decode and store the keystore file | |
- name: Decode Keystore | |
run: echo "$KEYSTORE_FILE" | base64 --decode > keystore/android.p12 | |
# Step 5: Build the app using Gradle | |
- name: Build APK | |
run: ./gradlew assembleRelease | |
# Sign APK | |
# Sign the APK using the .p12 keystore | |
- name: Sign APK | |
run: | | |
jarsigner -verbose \ | |
-keystore keystore/android.p12 \ | |
-storetype PKCS12 \ | |
-storepass "$KEYSTORE_PASSWORD" \ | |
-keypass "$KEY_PASSWORD" \ | |
app/build/outputs/apk/release/app-release-unsigned.apk \ | |
"$KEY_ALIAS" | |
# Step 7: Align APK using zipalign | |
- name: Align APK | |
run: | | |
${ANDROID_HOME}/build-tools/34.0.0/zipalign -v 4 \ | |
app/build/outputs/apk/release/app-release-unsigned.apk \ | |
app/build/outputs/apk/release/app-release-signed.apk | |
# Step 8: Upload APK to GitHub Release | |
- name: Upload APK to GitHub Release | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: app/build/outputs/apk/release/app-release-signed.apk | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ github.ref_name }} | |
name: Release ${{ github.ref_name }} | |
body: | | |
🚀 New release is available! | |
- **Version**: ${{ github.ref_name }} | |
- **APK File**: Attached below. |