@@ -88,10 +88,12 @@ jobs:
8888
8989 # Extract version components (assuming format like 1.0.5.3)
9090 IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
91- MAJOR=${VERSION_PARTS[0]}
92- MINOR=${VERSION_PARTS[1]}
93- PATCH=${VERSION_PARTS[2]}
94- BUILD=${VERSION_PARTS[3]}
91+
92+ # Set default values if parts are missing
93+ MAJOR=${VERSION_PARTS[0]:-1}
94+ MINOR=${VERSION_PARTS[1]:-0}
95+ PATCH=${VERSION_PARTS[2]:-0}
96+ BUILD=${VERSION_PARTS[3]:-0}
9597
9698 # Calculate versionCode (e.g., 10503 for 1.0.5.3)
9799 VERSION_CODE=$((MAJOR * 1000000 + MINOR * 10000 + PATCH * 100 + BUILD))
@@ -108,29 +110,63 @@ jobs:
108110 run : |
109111 cd android
110112
111- # Create signing configuration in app/build.gradle
112- cat >> app/build.gradle << 'EOF'
113+ # Backup original build.gradle
114+ cp app/build.gradle app/build.gradle.backup
115+
116+ # Create signing configuration script
117+ cat > add_signing.py << 'EOF'
118+ import re
113119
114- // Signing configuration added by GitHub Actions
115- if (project.hasProperty('RELEASE_STORE_FILE')) {
116- signingConfigs {
117- release {
118- storeFile file(RELEASE_STORE_FILE)
119- storePassword RELEASE_STORE_PASSWORD
120- keyAlias RELEASE_KEY_ALIAS
121- keyPassword RELEASE_KEY_PASSWORD
122- }
123- }
124-
125- buildTypes {
126- release {
127- signingConfig signingConfigs.release
128- }
120+ # Read the original build.gradle
121+ with open('app/build.gradle.backup', 'r') as f :
122+ content = f.read()
123+
124+ # Add signing configuration before buildTypes
125+ signing_config = """ // Signing configuration added by GitHub Actions
126+ if (project.hasProperty('RELEASE_STORE_FILE')) {
127+ signingConfigs {
128+ release {
129+ storeFile file(RELEASE_STORE_FILE)
130+ storePassword RELEASE_STORE_PASSWORD
131+ keyAlias RELEASE_KEY_ALIAS
132+ keyPassword RELEASE_KEY_PASSWORD
129133 }
130134 }
131- EOF
135+ }
136+
137+ " " "
138+
139+ # Insert signing config before buildTypes
140+ content = content.replace(' buildTypes {', signing_config + ' buildTypes {')
141+
142+ # Update release build type to use signing config
143+ old_release = " " " release {
144+ minifyEnabled false
145+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
146+ }"""
147+
148+ new_release = """ release {
149+ minifyEnabled false
150+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
151+ if (project.hasProperty('RELEASE_STORE_FILE')) {
152+ signingConfig signingConfigs.release
153+ }
154+ }"""
155+
156+ content = content.replace(old_release, new_release)
157+
158+ # Write updated content
159+ with open('app/build.gradle', 'w') as f :
160+ f.write(content)
161+
162+ print('Added signing configuration to build.gradle')
163+ EOF
164+
165+ # Run the script
166+ python3 add_signing.py
132167
133- echo "Added signing configuration to build.gradle"
168+ # Clean up
169+ rm add_signing.py
134170 shell : bash
135171
136172 - name : Build Debug APK
@@ -159,15 +195,27 @@ jobs:
159195 echo "Building unsigned release APK..."
160196 ./gradlew assembleRelease
161197 fi
198+
199+ # Verify the APK was created with the expected name
200+ VERSION="${{ steps.version.outputs.version }}"
201+ EXPECTED_APK="app/build/outputs/apk/release/lemon_push_v${VERSION}.apk"
202+ if [ -f "$EXPECTED_APK" ]; then
203+ echo "Release APK created successfully: $EXPECTED_APK"
204+ else
205+ echo "Error: Expected release APK not found at $EXPECTED_APK"
206+ echo "Listing release directory contents:"
207+ ls -la app/build/outputs/apk/release/
208+ exit 1
209+ fi
162210 shell : bash
163211
164212 - name : Prepare APK artifacts
165213 run : |
166214 mkdir -p release
167- # Copy debug APK
215+ # Copy debug APK (debug builds use the default name)
168216 cp android/app/build/outputs/apk/debug/app-debug.apk "release/${{ env.ENGLISH_NAME }}_v${{ steps.version.outputs.version }}_debug.apk"
169- # Copy release APK
170- cp android/app/build/outputs/apk/release/app-release .apk "release/${{ env.ENGLISH_NAME }}_v${{ steps.version.outputs.version }}_release.apk"
217+ # Copy release APK (release builds are renamed by applicationVariants.all)
218+ cp android/app/build/outputs/apk/release/lemon_push_v${{ steps.version.outputs.version }} .apk "release/${{ env.ENGLISH_NAME }}_v${{ steps.version.outputs.version }}_release.apk"
171219
172220 # Create checksums
173221 cd release
@@ -204,6 +252,9 @@ jobs:
204252 if : (startsWith(github.ref, 'refs/tags/') || github.event.inputs.release == 'true') && github.event_name != 'pull_request'
205253
206254 steps :
255+ - name : Checkout code
256+ uses : actions/checkout@v4
257+
207258 - name : Set version from tag or input
208259 id : version
209260 run : |
@@ -225,6 +276,12 @@ jobs:
225276 name : android-release-apk
226277 path : artifacts
227278
279+ - name : Download Debug APK
280+ uses : actions/download-artifact@v4
281+ with :
282+ name : android-debug-apk
283+ path : artifacts
284+
228285 - name : Download Checksums
229286 uses : actions/download-artifact@v4
230287 with :
@@ -239,13 +296,13 @@ jobs:
239296 ## ${{ env.APP_NAME }} Android v${{ steps.version.outputs.version }}
240297
241298 ### 下载链接:
242- - Android Release APK: lemon_push_v ${{ steps.version.outputs.version }}_release.apk
243- - Android Debug APK: lemon_push_v ${{ steps.version.outputs.version }}_debug.apk
299+ - Android Release APK: ${{ env.ENGLISH_NAME }}_v ${{ steps.version.outputs.version }}_release.apk
300+ - Android Debug APK: ${{ env.ENGLISH_NAME }}_v ${{ steps.version.outputs.version }}_debug.apk
244301 - 校验和文件: checksums.txt
245302
246303 ### 安装说明:
247304 #### Android:
248- 1. 下载 lemon_push_v ${{ steps.version.outputs.version }}_release.apk
305+ 1. 下载 ${{ env.ENGLISH_NAME }}_v ${{ steps.version.outputs.version }}_release.apk
249306 2. 在 Android 设备上启用"未知来源"安装
250307 3. 点击 APK 文件进行安装
251308
0 commit comments