1+ name : " android-release"
2+
3+ on :
4+ repository_dispatch :
5+ types : [build-release]
6+ workflow_dispatch :
7+ inputs :
8+ version :
9+ description : " Version number"
10+ required : true
11+ default : " v1.4.6"
12+ type : string
13+
14+ jobs :
15+ quick-build :
16+ runs-on : ubuntu-22.04
17+
18+ steps :
19+ - name : Checkout repository (mobile branch)
20+ uses : actions/checkout@v4
21+ with :
22+ repository : caolib/doki
23+ ref : mobile
24+ token : ${{ secrets.PAT_TOKEN }}
25+
26+ - name : Install pnpm
27+ uses : pnpm/action-setup@v4
28+ with :
29+ version : latest
30+
31+ - name : Install Node.js
32+ uses : actions/setup-node@v4
33+ with :
34+ node-version : " lts/*"
35+ cache : " pnpm"
36+
37+ - name : Cache pnpm store
38+ uses : actions/cache@v4
39+ with :
40+ path : ~/.pnpm-store
41+ key : ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
42+ restore-keys : |
43+ ${{ runner.os }}-pnpm-store-
44+
45+ - name : Install frontend dependencies
46+ run : pnpm install --no-frozen-lockfile
47+
48+ - name : Install Rust stable with Android targets
49+ uses : dtolnay/rust-toolchain@stable
50+ with :
51+ targets : aarch64-linux-android,armv7-linux-androideabi,i686-linux-android,x86_64-linux-android
52+
53+ - name : Rust cache
54+ uses : swatinem/rust-cache@v2
55+ with :
56+ workspaces : " ./src-tauri -> target"
57+ cache-all-crates : true
58+
59+ - name : Cache system dependencies
60+ uses : actions/cache@v4
61+ id : system-cache
62+ with :
63+ path : /var/cache/apt
64+ key : ${{ runner.os }}-apt-${{ hashFiles('**/package.json') }}
65+ restore-keys : |
66+ ${{ runner.os }}-apt-
67+
68+ - name : Install system dependencies
69+ if : steps.system-cache.outputs.cache-hit != 'true'
70+ run : |
71+ sudo apt-get update
72+ sudo apt-get install -y \
73+ libwebkit2gtk-4.1-dev \
74+ build-essential \
75+ curl \
76+ wget \
77+ file \
78+ libssl-dev \
79+ libayatana-appindicator3-dev \
80+ librsvg2-dev
81+
82+ - name : Cache Gradle wrapper and distributions
83+ uses : actions/cache@v4
84+ with :
85+ path : |
86+ ~/.gradle/wrapper
87+ ~/.gradle/caches
88+ src-tauri/gen/android/.gradle
89+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/gradle-wrapper.properties', '**/*.gradle*') }}
90+ restore-keys : |
91+ ${{ runner.os }}-gradle-
92+
93+ - name : Cache Android SDK
94+ uses : actions/cache@v4
95+ id : android-cache
96+ with :
97+ path : |
98+ ${{ env.ANDROID_HOME }}
99+ ~/.android
100+ key : ${{ runner.os }}-android-sdk-34-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
101+ restore-keys : |
102+ ${{ runner.os }}-android-sdk-34-
103+ ${{ runner.os }}-android-sdk-
104+
105+ - name : Setup Java JDK
106+ uses : actions/setup-java@v4
107+ with :
108+ distribution : " temurin"
109+ java-version : " 17"
110+
111+ - name : Setup Android SDK
112+ uses : android-actions/setup-android@v3
113+
114+ - name : Install Android SDK components
115+ if : steps.android-cache.outputs.cache-hit != 'true'
116+ run : |
117+ $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses || true
118+ $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager \
119+ "platform-tools" \
120+ "platforms;android-34" \
121+ "build-tools;34.0.0" \
122+ "ndk;26.1.10909125" \
123+ "cmdline-tools;latest"
124+
125+ - name : Set Android environment variables
126+ run : |
127+ echo "ANDROID_HOME=$ANDROID_HOME" >> $GITHUB_ENV
128+ echo "JAVA_HOME=$JAVA_HOME" >> $GITHUB_ENV
129+ echo "NDK_HOME=$ANDROID_HOME/ndk/26.1.10909125" >> $GITHUB_ENV
130+
131+ echo "Android环境变量设置:"
132+ echo "ANDROID_HOME: $ANDROID_HOME"
133+ echo "JAVA_HOME: $JAVA_HOME"
134+ echo "NDK_HOME: $ANDROID_HOME/ndk/26.1.10909125"
135+
136+ - name : Update version in tauri.conf.json
137+ run : |
138+ VERSION="${{ github.event.inputs.version }}"
139+ VERSION="${VERSION#v}"
140+ sed -i "s/\"version\": \".*\"/\"version\": \"$VERSION\"/" src-tauri/tauri.conf.json
141+ echo "Updated version to: $VERSION"
142+
143+ - name : Cache frontend build
144+ uses : actions/cache@v4
145+ id : frontend-cache
146+ with :
147+ path : |
148+ dist
149+ .next
150+ node_modules/.cache
151+ key : ${{ runner.os }}-frontend-${{ hashFiles('**/package.json', '**/pnpm-lock.yaml', 'src/**', 'public/**') }}
152+ restore-keys : |
153+ ${{ runner.os }}-frontend-
154+
155+ - name : Build frontend
156+ if : steps.frontend-cache.outputs.cache-hit != 'true'
157+ run : pnpm build
158+
159+ - name : Cache Tauri Android generation
160+ uses : actions/cache@v4
161+ id : tauri-android-cache
162+ with :
163+ path : src-tauri/gen/android
164+ key : ${{ runner.os }}-tauri-android-${{ hashFiles('src-tauri/tauri.conf.json', 'src-tauri/Cargo.toml') }}
165+ restore-keys : |
166+ ${{ runner.os }}-tauri-android-
167+
168+ - name : Initialize Tauri Android project (if needed)
169+ if : steps.tauri-android-cache.outputs.cache-hit != 'true'
170+ run : |
171+ if [ ! -d "src-tauri/gen/android" ]; then
172+ pnpm tauri android init
173+ fi
174+
175+ - name : Setup Gradle wrapper and fix download issues
176+ run : |
177+ cd src-tauri/gen/android
178+
179+ # 检查gradle-wrapper.properties
180+ if [ -f gradle/wrapper/gradle-wrapper.properties ]; then
181+ echo "当前Gradle配置:"
182+ cat gradle/wrapper/gradle-wrapper.properties
183+
184+ # 替换下载URL为更稳定的镜像
185+ sed -i 's|https://services.gradle.org/distributions/|https://downloads.gradle.org/distributions/|g' gradle/wrapper/gradle-wrapper.properties
186+
187+ echo "修改后的Gradle配置:"
188+ cat gradle/wrapper/gradle-wrapper.properties
189+ fi
190+
191+ # 验证gradlew权限
192+ chmod +x gradlew
193+
194+ # 尝试预下载Gradle(带重试机制)
195+ echo "预下载Gradle包..."
196+ for i in {1..3}; do
197+ echo "尝试 $i/3..."
198+ if ./gradlew --version; then
199+ echo "✅ Gradle下载成功"
200+ break
201+ else
202+ echo "⚠️ 第$i次尝试失败,等待10秒后重试..."
203+ sleep 10
204+ fi
205+
206+ if [ $i -eq 3 ]; then
207+ echo "❌ Gradle下载失败,尝试手动下载..."
208+
209+ # 手动下载Gradle
210+ GRADLE_VERSION=$(grep "distributionUrl" gradle/wrapper/gradle-wrapper.properties | cut -d'/' -f6 | cut -d'-' -f2)
211+ echo "检测到Gradle版本: $GRADLE_VERSION"
212+
213+ mkdir -p ~/.gradle/wrapper/dists/gradle-$GRADLE_VERSION-bin
214+ cd ~/.gradle/wrapper/dists/gradle-$GRADLE_VERSION-bin
215+
216+ # 尝试多个下载源
217+ GRADLE_URLS=(
218+ "https://downloads.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip"
219+ "https://github.com/gradle/gradle/releases/download/v$GRADLE_VERSION.0/gradle-$GRADLE_VERSION-bin.zip"
220+ "https://services.gradle.org/distributions/gradle-$GRADLE_VERSION-bin.zip"
221+ )
222+
223+ for url in "${GRADLE_URLS[@]}"; do
224+ echo "尝试从 $url 下载..."
225+ if wget -q --timeout=30 --tries=2 "$url"; then
226+ echo "✅ 手动下载成功"
227+ break
228+ fi
229+ done
230+ fi
231+ done
232+
233+ - name : Setup Android signing (if secrets available)
234+ run : |
235+ cd src-tauri
236+ if [ -n "${{ secrets.DOKI_KEYSTORE_BASE64 }}" ]; then
237+ base64 -d <<< "${{ secrets.DOKI_KEYSTORE_BASE64 }}" > doki-release-key.keystore
238+ echo "✅ 密钥文件已恢复"
239+ else
240+ echo "⚠️ 未找到签名密钥,将构建未签名APK"
241+ fi
242+
243+ # 移除特定架构选择,构建所有架构
244+ - name : Install all Android Rust targets
245+ run : |
246+ echo "安装所有Android Rust目标..."
247+ rustup target add aarch64-linux-android
248+ rustup target add armv7-linux-androideabi
249+ rustup target add i686-linux-android
250+ rustup target add x86_64-linux-android
251+ echo "✅ 所有Android Rust目标已安装"
252+
253+ - name : Build Android APK for all platforms
254+ run : |
255+ echo "开始构建Android APK (所有平台)..."
256+ echo "使用package.json中的构建脚本..."
257+
258+ # 设置Gradle选项
259+ export GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.parallel=false -Dorg.gradle.jvmargs=-Xmx2g"
260+
261+ # 使用package.json中定义的构建脚本,包含自动重命名
262+ pnpm run build:android
263+
264+ - name : List generated APK files
265+ run : |
266+ echo "检查生成的APK文件..."
267+
268+ # 检查原始APK目录
269+ ORIGINAL_APK_DIR="src-tauri/gen/android/app/build/outputs/apk/universal/release"
270+ if [ -d "$ORIGINAL_APK_DIR" ]; then
271+ echo "原始APK目录内容:"
272+ ls -la "$ORIGINAL_APK_DIR"
273+ fi
274+
275+ echo ""
276+ echo "查找所有APK文件(包括重命名后的):"
277+ find . -name "*.apk" -type f -exec ls -lh {} \; | while read line; do
278+ echo " $line"
279+ done
280+
281+ APK_COUNT=$(find . -name "*.apk" -type f | wc -l)
282+ echo ""
283+ echo "总共找到 $APK_COUNT 个APK文件"
284+
285+ - name : Create Release and Upload APKs
286+ uses : softprops/action-gh-release@v2
287+ if : startsWith(github.event.inputs.version, 'v')
288+ with :
289+ tag_name : ${{ github.event.inputs.version }}
290+ name : Release ${{ github.event.inputs.version }}
291+ draft : false
292+ prerelease : false
293+ files : |
294+ **/*.apk
295+ env :
296+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments