From e39828ed56d68346f97aa24cdf44ee9e961c21b5 Mon Sep 17 00:00:00 2001 From: sravan Date: Tue, 8 Sep 2026 16:35:39 +0530 Subject: [PATCH] Android CI: fail the build on a Gradle error + surface the real cause MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The build step ended with `find … *.apk`, which exits 0 even when Gradle failed and no APK exists — so Codemagic marked a failed Gradle run as a green build with no artifact. Now: capture gradle output, use PIPESTATUS to detect failure, print the "What went wrong" / FAILURE block, exit non-zero, and assert an APK exists. Co-Authored-By: Claude Opus 4.8 --- codemagic.yaml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/codemagic.yaml b/codemagic.yaml index a993c13..fb75c03 100644 --- a/codemagic.yaml +++ b/codemagic.yaml @@ -231,12 +231,26 @@ workflows: - name: Build the debug APK script: | + set -e cd mobile/android chmod +x ./gradlew # Debug build type is auto-signed with the Android debug keystore → directly installable, no Play # account or upload key needed. (A signed release AAB for the Play Store is a later, separate step.) - ./gradlew assembleDebug --stacktrace + # Capture the output so that, on failure, we surface Gradle's actual "What went wrong" block instead + # of a wall of internal stack frames — and FAIL the step (a trailing `find` used to exit 0 and mask it). + set +e + ./gradlew assembleDebug --stacktrace 2>&1 | tee /tmp/gradle.log + STATUS=${PIPESTATUS[0]} + set -e + if [ "$STATUS" != "0" ]; then + echo "======================= GRADLE FAILURE =======================" + grep -n -A 25 "What went wrong" /tmp/gradle.log || true + grep -n -A 3 "FAILURE:" /tmp/gradle.log || true + echo "==============================================================" + exit 1 + fi echo "APK(s):"; find app/build/outputs -name "*.apk" + test -n "$(find app/build/outputs -name '*.apk' -print -quit)" || { echo "ERROR: no APK produced"; exit 1; } artifacts: - mobile/android/app/build/outputs/**/*.apk # Download the APK from the build page. To get it emailed like TestFlight, add a `publishing.email` block