-
Notifications
You must be signed in to change notification settings - Fork 0
198 lines (174 loc) · 7.8 KB
/
android-deploy.yml
File metadata and controls
198 lines (174 loc) · 7.8 KB
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
name: FxFiles Android Deploy
on:
workflow_dispatch:
release:
types: [published]
jobs:
deploy-android:
runs-on: ubuntu-latest
steps:
- name: Free Disk Space
run: |
echo "Disk space before cleanup:"
df -h
# Remove unused software to free up space
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo rm -rf /usr/local/share/boost
sudo rm -rf /usr/share/swift
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
# Remove Docker images
sudo docker image prune --all --force || true
# Clean apt cache
sudo apt-get clean
echo "Disk space after cleanup:"
df -h
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.38.5'
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
# The fllama plugin pins NDK 28.0.12433566. The GitHub Actions ubuntu-latest
# image ships some NDKs pre-installed but doesn't necessarily include this
# exact build, and the license for it isn't pre-accepted, which causes
# `flutter build appbundle` to fail at the Gradle configure step:
# "License for package NDK (Side by side) 28.0.12433566 not accepted"
# android-actions/setup-android puts sdkmanager on PATH, accepts licenses,
# and installs the listed packages. Using it is more robust than calling
# sdkmanager directly — the runner's PATH varies across image revisions.
- name: Install Android NDK 28.0.12433566 (accept licenses)
uses: android-actions/setup-android@v3
with:
packages: 'ndk;28.0.12433566'
accept-android-sdk-licenses: true
- name: Verify NDK installed
run: ls -la "$ANDROID_HOME/ndk" || true
# fllama's android/build.gradle pins `cmake { version "3.31.0" }`, and
# AGP requires that exact version — it won't fall back to 3.22.1 (which
# is what sdkmanager would auto-install). sdkmanager doesn't have 3.31.0
# in its repo. Download the official Kitware binary and drop it where
# AGP looks for it ($ANDROID_HOME/cmake/<version>/). The upstream tarball
# doesn't bundle ninja but AGP needs it next to cmake, so install ninja
# via apt and symlink it into bin/.
- name: Install CMake 3.31.0 (fllama requires this exact version)
run: |
CMAKE_VERSION="3.31.0"
SDK_CMAKE_DIR="$ANDROID_HOME/cmake/$CMAKE_VERSION"
if [ -x "$SDK_CMAKE_DIR/bin/cmake" ]; then
echo "CMake $CMAKE_VERSION already at $SDK_CMAKE_DIR"
else
echo "Downloading CMake $CMAKE_VERSION from Kitware"
mkdir -p "$SDK_CMAKE_DIR"
curl -fsSL "https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz" \
| tar -xz --strip-components=1 -C "$SDK_CMAKE_DIR"
fi
if [ ! -x "$SDK_CMAKE_DIR/bin/ninja" ]; then
echo "Installing ninja and placing it in $SDK_CMAKE_DIR/bin/"
sudo apt-get update
sudo apt-get install -y ninja-build
cp "$(command -v ninja)" "$SDK_CMAKE_DIR/bin/ninja"
fi
"$SDK_CMAKE_DIR/bin/cmake" --version
"$SDK_CMAKE_DIR/bin/ninja" --version
echo "Available CMake versions in SDK:"
ls -la "$ANDROID_HOME/cmake/"
- name: Flutter Doctor
run: flutter doctor -v
- name: Get Dependencies
run: flutter pub get
- name: Set Production Package Name
run: |
echo "Changing package name from land.fx.files.dev to land.fx.files for production..."
# Update build.gradle.kts
sed -i 's/namespace = "land.fx.files.dev"/namespace = "land.fx.files"/' android/app/build.gradle.kts
sed -i 's/applicationId = "land.fx.files.dev"/applicationId = "land.fx.files"/' android/app/build.gradle.kts
# Update package declarations in all Kotlin files
for file in android/app/src/main/kotlin/land/fx/files/dev/*.kt; do
sed -i 's/^package land.fx.files.dev$/package land.fx.files/' "$file"
echo "Updated package in: $file"
done
# Move all Kotlin files to production package directory
mkdir -p android/app/src/main/kotlin/land/fx/files
mv android/app/src/main/kotlin/land/fx/files/dev/*.kt android/app/src/main/kotlin/land/fx/files/
rm -rf android/app/src/main/kotlin/land/fx/files/dev
echo "Package name updated to land.fx.files"
echo "Verifying changes..."
grep -n "namespace\|applicationId" android/app/build.gradle.kts
ls -la android/app/src/main/kotlin/land/fx/files/
head -1 android/app/src/main/kotlin/land/fx/files/*.kt
- name: Get Package Version
run: |
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //' | tr -d ' ')
echo "APP_VERSION=$VERSION" >> $GITHUB_ENV
echo "App version: $VERSION"
- name: Decode Keystore
run: echo "${{ secrets.SIGNING_KEY_BASE64 }}" | base64 -d > ${{ github.workspace }}/android/app/signingKey.jks
- name: Create key.properties
run: |
echo "storePassword=${{ secrets.KEY_STORE_PASSWORD }}" > ${{ github.workspace }}/android/key.properties
echo "keyPassword=${{ secrets.KEY_PASSWORD }}" >> ${{ github.workspace }}/android/key.properties
echo "keyAlias=${{ secrets.KEY_ALIAS }}" >> ${{ github.workspace }}/android/key.properties
echo "storeFile=${{ github.workspace }}/android/app/signingKey.jks" >> ${{ github.workspace }}/android/key.properties
- name: Build Android App Bundle
run: flutter build appbundle --release
- name: List Build Output
run: ls -la ${{ github.workspace }}/build/app/outputs/bundle/release/
- name: Get Release Info
id: get-release-info
uses: actions/github-script@v5
with:
script: |
let releaseId = 0;
try {
const release = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
releaseId = release.data.id;
} catch (error) {
console.log('Error fetching latest release: ', error.message);
}
return releaseId;
- name: Print Release ID
run: echo "Release ID is ${{ steps.get-release-info.outputs.result }}"
- name: Upload AAB to Release
uses: actions/github-script@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const fs = require('fs');
const path = require('path');
const directory = '${{ github.workspace }}/build/app/outputs/bundle/release';
const files = fs.readdirSync(directory);
for (const file of files) {
if (file.endsWith('.aab')) {
const filePath = path.join(directory, file);
console.log(`Uploading ${file}...`);
await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ steps.get-release-info.outputs.result }},
name: `FxFiles_v${{ env.APP_VERSION }}_${file}`,
data: fs.readFileSync(filePath)
});
}
}
# Optional: Upload to Google Play using Fastlane or r0adkll/upload-google-play
# - name: Upload to Google Play
# uses: r0adkll/upload-google-play@v1
# with:
# serviceAccountJsonPlainText: ${{ secrets.GOOGLE_PLAY_SERVICE_ACCOUNT_JSON }}
# packageName: land.fx.files
# releaseFiles: build/app/outputs/bundle/release/app-release.aab
# track: internal
# status: completed