fix(ci): stop the resource guard from lying when it cannot inspect the APK

The guard added in the previous commit reported all three drawables as
missing on its first run, including ic_stat_pluriwave -- which is
verifiably present: it was read out of the base.apk pulled off the device
byte by byte. The step also finished in 0s, so it never opened the file at
all. Either the APK is not at the assumed path on this runner or unzip is
unavailable, and the failing pipeline silently produced an empty listing
that every grep then "failed" against.

A guard that lies is worse than no guard: it sends you hunting ghosts,
which is exactly the failure mode this whole episode has been about.

It now verifies its own preconditions before judging anything:
- the APK must exist, and if it does not the step prints where the APKs
  actually are (find over build/app/outputs) instead of guessing;
- it needs unzip or python3, and says so plainly if neither is there;
- an empty listing is treated as "inspection unreliable", not as
  "everything is missing";
- it dumps the real res/drawable inventory before the verdict, so a
  future failure is readable without another round trip.

Matching is now exact (grep -qx) rather than substring.

The logic was run locally against the real 45MB base.apk taken off the
device: ic_stat_pluriwave OK, ic_auto_eq_on and ic_auto_eq_off missing --
which is precisely what an independent zipfile inspection of the same APK
reported yesterday. The check agrees with reality before shipping.
This commit is contained in:
2026-08-07 12:27:40 +02:00
parent ec6ccb2db8
commit 0a47c327f1
+57 -5
View File
@@ -145,24 +145,76 @@ jobs:
# entre el 31-07 (commit 2540556) y el 07-08 sin que nada lo detectara.
#
# Anadir un drawable nuevo referenciado por nombre => anadirlo aqui.
# Guardian de recursos: el APK debe contener los drawables que el codigo
# resuelve POR NOMBRE en runtime (getResources().getIdentifier).
#
# Un nombre que no resuelve devuelve id 0, y eso no falla la
# compilacion: falla en el coche. PlaybackStateCompat.CustomAction
# .Builder lanza con icono 0, ese throw aborta AudioService.setState
# antes de activar la sesion de medios, y Android Auto se queda con la
# interfaz congelada. Paso exactamente eso desde el 31-07 (commit
# 2540556) sin que nada lo detectara.
#
# La primera version de este paso daba FALSOS POSITIVOS: no comprobaba
# que el APK existiera ni que unzip estuviera disponible, asi que
# cualquier fallo de la tuberia se reportaba como "faltan todos los
# recursos". Un guardian que miente es peor que no tener guardian:
# manda a buscar fantasmas. De ahi que ahora verifique primero sus
# propias herramientas y vuelque el inventario real antes de juzgar.
#
# Anadir un drawable nuevo referenciado por nombre => anadirlo aqui.
- name: Verificar recursos criticos en el APK
run: |
set -u
APK=build/app/outputs/flutter-apk/app-release.apk
if [ ! -f "$APK" ]; then
echo "El APK no esta donde se esperaba: $APK"
echo "Contenido de build/app/outputs:"
find build/app/outputs -name '*.apk' 2>/dev/null || echo " (nada)"
exit 1
fi
echo "APK: $APK ($(wc -c < "$APK") bytes)"
if command -v unzip >/dev/null 2>&1; then
LISTADO=$(unzip -Z1 "$APK")
elif command -v python3 >/dev/null 2>&1; then
LISTADO=$(python3 - "$APK" <<'PYZIP'
import zipfile, sys
for nombre in zipfile.ZipFile(sys.argv[1]).namelist():
print(nombre)
PYZIP
)
else
echo "Ni unzip ni python3 disponibles: no se puede inspeccionar el APK."
exit 1
fi
if [ -z "$LISTADO" ]; then
echo "El listado del APK salio vacio; la inspeccion no es fiable."
exit 1
fi
echo "Drawables en el APK:"
echo "$LISTADO" | grep "^res/drawable" || echo " (ninguno)"
FALTAN=0
for RECURSO in ic_auto_eq_on ic_auto_eq_off ic_stat_pluriwave; do
if unzip -l "$APK" | grep -q "res/drawable/$RECURSO.xml"; then
echo "OK res/drawable/$RECURSO.xml"
if echo "$LISTADO" | grep -qx "res/drawable/$RECURSO.xml"; then
echo "OK $RECURSO"
else
echo "FALTA res/drawable/$RECURSO.xml"
FALTAN=1
echo "FALTA $RECURSO"
FALTAN=$((FALTAN + 1))
fi
done
if [ "$FALTAN" -ne 0 ]; then
echo ""
echo "Hay drawables resueltos por nombre que NO estan en el APK."
echo "$FALTAN drawable(s) resueltos por nombre NO estan en el APK."
echo "En runtime resolveran a id 0 y tumbaran la sesion de medios."
exit 1
fi
echo "Todos los recursos criticos viajan en el APK."
- name: Build AAB release
run: flutter build appbundle --release