Skip to content

Commit

Permalink
🐛 修复 android ci
Browse files Browse the repository at this point in the history
  • Loading branch information
hanasa2023 committed Nov 29, 2024
1 parent 16a6ebc commit a1caea8
Showing 1 changed file with 42 additions and 19 deletions.
61 changes: 42 additions & 19 deletions .github/workflows/android-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: 'publish android'

on:
push:
branches:
- main
tags:
- '*'

workflow_dispatch:

Expand All @@ -29,7 +29,9 @@ jobs:
uses: android-actions/setup-android@v3

- name: Install NDK
run: sdkmanager "ndk;27.0.11902837"
run: |
sdkmanager "ndk;27.0.11902837"
echo "NDK_HOME=$ANDROID_HOME/ndk/27.0.11902837" >> $GITHUB_ENV
- name: setup node
uses: actions/setup-node@v4
Expand All @@ -41,42 +43,63 @@ jobs:
with:
targets: aarch64-linux-android,armv7-linux-androideabi,i686-linux-android,x86_64-linux-android

- name: Add NDK targets and tools to PATH
run: |
echo "$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
- name: Install dependencies
run: pnpm install

- name: Build app bundle
run: pnpm tauri android build -v
- name: Init android app
run: pnpm tauri android init
env:
NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/27.0.11902837

- name: Extract android signing key from env
run: |
echo "${{ secrets.ANDROID_RELEASE_KEYSTORE }}" > src-tauri/gen/android/release.jks.base64
base64 -d src-tauri/gen/android/release.jks.base64 > src-tauri/gen/android/release.decrypted.jks
- name: Set Icon
run: pnpm tauri icon src-tauri/icons/icon.png

- name: Sign APK
- name: setup Android signing
run: |
${{ env.ANDROID_HOME }}/build-tools/34.0.0/apksigner sign --ks src-tauri/gen/android/release.decrypted.jks \
--ks-key-alias ${{ secrets.ANDROID_RELEASE_KEY }} \
--ks-pass pass:${{ secrets.ANDROID_RELEASE_PASSWORD }} \
--key-pass pass:${{ secrets.ANDROID_RELEASE_KEY_PASSWORD }} \
--out src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-signed.apk \
src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk
cd src-tauri/gen/android
echo "keyAlias=${{ secrets.ANDROID_KEY_ALIAS }}" > keystore.properties
echo "password=${{ secrets.ANDROID_KEY_PASSWORD }}" >> keystore.properties
base64 -d <<< "${{ secrets.ANDROID_KEY_BASE64 }}" > $RUNNER_TEMP/keystore.jks
echo "storeFile=$RUNNER_TEMP/keystore.jks" >> keystore.properties
sed -i '2i import java.io.FileInputStream' ./app/build.gradle.kts
sed -i '30i val keystorePropertiesFile = rootProject.file("keystore.properties")\n
val keystoreProperties = Properties()\n
if (keystorePropertiesFile.exists()) {\n
keystoreProperties.load(FileInputStream(keystorePropertiesFile))\n
}\n
keyAlias = keystoreProperties["keyAlias"] as String\n
keyPassword = keystoreProperties["password"] as String\n
storeFile = file(keystoreProperties["storeFile"] as String)\n
storePassword = keystoreProperties["password"] as String\n' ./app/build.gradle.kts
sed -i '55i signingConfig = signingConfigs.getByName("release")' ./app/build.gradle.kts
- name: Build app bundle
run: pnpm tauri android build -v
env:
NDK_HOME: ${{ env.ANDROID_HOME }}/ndk/27.0.11902837

- name: Get Node project version
id: package-version
uses: martinbeentjes/[email protected]

- name: Rename APK file
run: |
mv ./src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-signed.apk ./src-tauri/gen/android/app/build/outputs/apk/universal/release/myappliation-${{ steps.package-version.outputs.current-version}}.apk
APK_VERSION=$(echo "${{ steps.package-version.outputs.current-version}}" | tr -d '\n')
mv ./src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release-unsigned.apk ./src-tauri/gen/android/app/build/outputs/apk/universal/release/matcha-${APK_VERSION}.apk
- name: Publish
uses: softprops/action-gh-release@v1
with:
draft: true
name: App v${{ steps.package-version.outputs.current-version}}
name: matcha v${{ steps.package-version.outputs.current-version}}
tag_name: v${{ steps.package-version.outputs.current-version}}
generate_release_notes: true
files: |
./src-tauri/gen/android/app/build/outputs/apk/universal/release/myapplication-${{ steps.package-version.outputs.current-version}}.apk
./src-tauri/gen/android/app/build/outputs/apk/universal/release/matcha-${{ steps.package-version.outputs.current-version}}.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit a1caea8

Please sign in to comment.