@@ -122,29 +122,17 @@ with open('app/build.gradle.backup', 'r') as f:
122122 content = f.read()
123123
124124# 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
133- }
134- }
135- }
136-
137- " " "
125+ signing_config = " // Signing configuration added by GitHub Actions\n if (project.hasProperty('RELEASE_STORE_FILE')) {\n signingConfigs {\n release {\n storeFile file(RELEASE_STORE_FILE)\n storePassword RELEASE_STORE_PASSWORD\n keyAlias RELEASE_KEY_ALIAS\n keyPassword RELEASE_KEY_PASSWORD\n }\n }\n }\n\n"
138126
139127# Insert signing config before buildTypes
140- content = content.replace(' buildTypes {', signing_config + ' buildTypes {')
128+ if ' buildTypes {' in content :
129+ content = content.replace(' buildTypes {', signing_config + ' buildTypes {')
130+ else :
131+ print("Error : Could not find buildTypes section in build.gradle")
132+ exit(1)
141133
142134# 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-
135+ old_release_pattern = r"(\s+release\s+\{[\s\S]*?minifyEnabled\s+\w+\s*[\s\S]*?proguardFiles\s+.*?[\s\S]*?\})"
148136new_release = """ release {
149137 minifyEnabled false
150138 proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
@@ -153,7 +141,19 @@ new_release = """ release {
153141 }
154142 }"""
155143
156- content = content.replace(old_release, new_release)
144+ # Try to replace the release build type
145+ if re.search(old_release_pattern, content) :
146+ content = re.sub(old_release_pattern, new_release, content)
147+ else :
148+ print("Warning : Could not find release build type to update")
149+ # Try to find and update just the signing config part
150+ if 'release {' in content and 'signingConfig' not in content :
151+ # Add signing config to existing release block
152+ content = re.sub(
153+ r'(\s+release\s+\{[\s\S]*?proguardFiles\s+.*?[\s\S]*?\})',
154+ r'\1\n if (project.hasProperty(\'RELEASE_STORE_FILE\')) {\n signingConfig signingConfigs.release\n }',
155+ content
156+ )
157157
158158# Write updated content
159159with open('app/build.gradle', 'w') as f :
165165 # Run the script
166166 python3 add_signing.py
167167
168+ # Verify the changes were applied
169+ if grep -q "signingConfigs" app/build.gradle; then
170+ echo "Signing configuration added successfully"
171+ else
172+ echo "Warning : Signing configuration may not have been added correctly"
173+ echo "Checking build.gradle for buildTypes section:"
174+ grep -A 10 "buildTypes" app/build.gradle || echo "buildTypes section not found"
175+ fi
176+
168177 # Clean up
169178 rm add_signing.py
170179 shell : bash
173182 run : |
174183 cd android
175184 ./gradlew assembleDebug
185+
186+ # Check if debug APK was created
187+ echo "Checking for debug APK..."
188+ ls -la app/build/outputs/apk/debug/
189+
190+ # Verify the debug APK exists
191+ DEBUG_APK="app/build/outputs/apk/debug/app-debug.apk"
192+ if [ -f "$DEBUG_APK" ]; then
193+ echo "Debug APK created successfully: $DEBUG_APK"
194+ else
195+ echo "Error: Debug APK not found at $DEBUG_APK"
196+ echo "Contents of debug directory:"
197+ ls -la app/build/outputs/apk/debug/
198+ exit 1
199+ fi
176200 shell : bash
177201
178202 - name : Build Release APK
@@ -196,14 +220,23 @@ EOF
196220 ./gradlew assembleRelease
197221 fi
198222
199- # Verify the APK was created with the expected name
223+ # Check if APK was created
224+ echo "Checking for release APK..."
225+ ls -la app/build/outputs/apk/release/
226+
227+ # Try to find the APK with expected name or fallback to default
200228 VERSION="${{ steps.version.outputs.version }}"
201229 EXPECTED_APK="app/build/outputs/apk/release/lemon_push_v${VERSION}.apk"
230+ FALLBACK_APK="app/build/outputs/apk/release/app-release.apk"
231+
202232 if [ -f "$EXPECTED_APK" ]; then
203- echo "Release APK created successfully: $EXPECTED_APK"
233+ echo "Found release APK with expected name: $EXPECTED_APK"
234+ elif [ -f "$FALLBACK_APK" ]; then
235+ echo "Found release APK with default name, renaming to expected name..."
236+ cp "$FALLBACK_APK" "$EXPECTED_APK"
204237 else
205- echo "Error: Expected release APK not found at $EXPECTED_APK "
206- echo "Listing release directory contents :"
238+ echo "Error: No release APK found! "
239+ echo "Contents of release directory:"
207240 ls -la app/build/outputs/apk/release/
208241 exit 1
209242 fi
217250 # Copy release APK (release builds are renamed by applicationVariants.all)
218251 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"
219252
253+ # Verify APKs exist
254+ if [ ! -f "release/${{ env.ENGLISH_NAME }}_v${{ steps.version.outputs.version }}_debug.apk" ]; then
255+ echo "Error: Debug APK not found!"
256+ ls -la android/app/build/outputs/apk/debug/
257+ exit 1
258+ fi
259+
260+ if [ ! -f "release/${{ env.ENGLISH_NAME }}_v${{ steps.version.outputs.version }}_release.apk" ]; then
261+ echo "Error: Release APK not found!"
262+ ls -la android/app/build/outputs/apk/release/
263+ exit 1
264+ fi
265+
220266 # Create checksums
221267 cd release
222268 sha256sum *.apk > checksums.txt
245291 name : android-checksums
246292 path : release/checksums.txt
247293 retention-days : 90
294+
295+ - name : Clean up temporary files
296+ if : always()
297+ run : |
298+ cd android
299+ # Clean up keystore if it exists
300+ if [ -f "app/keystore.jks" ]; then
301+ echo "Removing temporary keystore file"
302+ rm app/keystore.jks
303+ fi
304+
305+ # Restore original build.gradle if backup exists
306+ if [ -f "app/build.gradle.backup" ]; then
307+ echo "Restoring original build.gradle"
308+ mv app/build.gradle.backup app/build.gradle
309+ fi
310+ shell : bash
248311
249312 create-release :
250313 needs : build-android
0 commit comments