-
Notifications
You must be signed in to change notification settings - Fork 7
215 lines (186 loc) · 7.63 KB
/
android-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Android Build
on:
release:
types: [created]
push:
branches:
- test
env:
ACTIONS_RUNNER_DEBUG: true
ACTIONS_STEP_DEBUG: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
cache: 'npm'
- name: Install deps
run: |
npm ci
npm install -g @ionic/cli native-run cordova-res
- name: Set up environment
run: |
if [[ ${{ github.event_name }} == 'release' ]]; then
cp .env.production.example .env
else
cp .env.development.example .env
fi
source .env
echo "VITE_ANDROID_APPLICATION_ID=$VITE_ANDROID_APPLICATION_ID" >> $GITHUB_ENV
echo "VITE_APP_NAME=$VITE_APP_NAME" >> $GITHUB_ENV
echo "VITE_APP_URL=$VITE_APP_URL" >> $GITHUB_ENV
- name: Debug environment
run: |
echo "Environment variables:"
echo "VITE_APP_NAME: ${{ env.VITE_APP_NAME }}"
echo "VITE_ANDROID_APPLICATION_ID: ${{ env.VITE_ANDROID_APPLICATION_ID }}"
echo "VITE_APP_URL: ${{ env.VITE_APP_URL }}"
- name: Set VERSION and VERSION_CODE
run: |
if [[ ${{ github.event_name }} == 'release' ]]; then
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
echo "VERSION_CODE=$(git rev-list --count HEAD)" >> $GITHUB_ENV
else
echo "VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
echo "VERSION_CODE=$(git rev-list --count HEAD)" >> $GITHUB_ENV
fi
- name: Set up Android project structure
run: |
mkdir -p android/app/src/main/java
mkdir -p android/app/src/main/res/values
- name: Run pre-build script
run: |
npm run prebuild
- name: Verify Android project structure
run: |
echo "Android project structure:"
tree android/app/src/main
echo "MainActivity.java contents:"
cat android/app/src/main/java/${VITE_ANDROID_APPLICATION_ID//./\/}/MainActivity.java
echo "AndroidManifest.xml package and URL:"
grep 'package=' android/app/src/main/AndroidManifest.xml
grep 'android:host=' android/app/src/main/AndroidManifest.xml
echo "build.gradle applicationId and version:"
grep 'applicationId' android/app/build.gradle
grep 'versionCode' android/app/build.gradle
grep 'versionName' android/app/build.gradle
echo "MainActivity.java package:"
grep 'package' android/app/src/main/java/${VITE_ANDROID_APPLICATION_ID//./\/}/MainActivity.java
echo "strings.xml app name:"
grep 'app_name' android/app/src/main/res/values/strings.xml
echo "capacitor.config.json package name:"
grep 'packageName' capacitor.config.json || echo "capacitor.config.json not found"
- name: Build Android app
run: |
source .env
ionic cap sync android
if [[ ${{ github.event_name }} == 'release' ]]; then
ionic cap build android --no-interactive --prod
else
ionic cap build android --no-interactive
fi
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Make gradlew executable
run: chmod +x ./android/gradlew
- name: Build with Gradle
run: |
cd android
./gradlew assembleRelease --info \
-PversionCode=${{ env.VERSION_CODE }} \
-PversionName=${{ env.VERSION }} \
-PappName="${{ env.VITE_APP_NAME }}" \
-PapplicationId="${{ env.VITE_ANDROID_APPLICATION_ID }}" \
-PappUrl="${{ env.VITE_APP_URL }}"
- name: Check AndroidManifest.xml after Gradle build
run: |
echo "AndroidManifest.xml contents after Gradle build:"
cat android/app/src/main/AndroidManifest.xml
- name: Set up Android SDK
uses: android-actions/setup-android@v3
- name: Decode Keystore
run: |
echo ${{ secrets.ANDROID_KEYSTORE }} | base64 --decode > my-release-key.keystore
shell: bash
- name: Verify Keystore
run: |
keytool -list -v -keystore my-release-key.keystore -storepass ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
shell: bash
- name: Sign APK
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner sign --ks my-release-key.keystore --ks-pass pass:${{ secrets.ANDROID_KEYSTORE_PASSWORD }} --key-pass pass:${{ secrets.ANDROID_KEY_PASSWORD }} --out android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk android/app/build/outputs/apk/release/app-release-unsigned.apk
shell: bash
- name: Verify APK
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/apksigner verify android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
shell: bash
- name: Upload APK to GitHub Release
if: github.event_name == 'release'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
asset_name: ${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
asset_content_type: application/vnd.android.package-archive
- name: Upload APK as artifact
if: github.event_name == 'push'
uses: actions/upload-artifact@v3
with:
name: app-release-dev
path: android/app/build/outputs/apk/release/${{ env.VITE_APP_NAME }}-${{ env.VERSION }}.apk
- name: Check AndroidManifest.xml
run: |
cat android/app/src/main/AndroidManifest.xml
- name: Debug Build Environment
run: |
echo "VITE_ANDROID_APPLICATION_ID: ${{ env.VITE_ANDROID_APPLICATION_ID }}"
echo "Gradle Properties:"
cat android/gradle.properties
echo "Build Gradle Contents:"
cat android/app/build.gradle
- name: Check APK contents
run: |
APK_DIR="android/app/build/outputs/apk/release"
APK_FILE=$(find $APK_DIR -name "*.apk" | head -n 1)
if [ -f "$APK_FILE" ]; then
echo "APK file found: $APK_FILE"
echo "APK contents:"
unzip -l "$APK_FILE"
echo "AndroidManifest.xml contents:"
if unzip -p "$APK_FILE" AndroidManifest.xml > manifest.xml; then
if [ -s manifest.xml ]; then
$ANDROID_SDK_ROOT/build-tools/33.0.0/aapt dump xmltree manifest.xml || echo "aapt command failed"
else
echo "Extracted AndroidManifest.xml is empty"
fi
else
echo "Failed to extract AndroidManifest.xml from APK"
fi
else
echo "No APK file found in $APK_DIR"
ls -R $APK_DIR
fi
- name: Check aapt version
run: |
$ANDROID_SDK_ROOT/build-tools/33.0.0/aapt version || echo "aapt not found or failed to run"