Modern Apps git

MAOS.git

Public
git clone https://git.maproj.org/MAOS.git
main ▾

MAOS.git / scripts / collect-apks.sh

collect-apks.sh66 lines · 2.2 KiBRaw
1#!/usr/bin/env bash
2#
3# collect-apks.sh — populate vendor/modern-apps/prebuilts/ with the Modern Apps
4# release APKs before an AOSP build.
5#
6# The APKs are git-ignored (large binaries, reproducible from the Modern-Apps repo),
7# so this must run on the build host before `m`/`make`.
8#
9# Usage:
10# scripts/collect-apks.sh <path>
11#
12# <path> may be:
13# - a Modern-Apps repo root (looks in distribution_apks/ and each module's
14# build/outputs/apk/release/)
15# - a distribution_apks/ dir (produced by Modern-Apps release.sh)
16# - any dir containing *-release.apk files
17#
18set -euo pipefail
19
20SRC="${1:?usage: collect-apks.sh <path to Modern-Apps repo, its distribution_apks dir, or a dir of *-release.apk>}"
21DEST="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/prebuilts"
22mkdir -p "$DEST"
23
24
25# The app list is the one in build-maos.sh, parsed rather than duplicated. These two
26# arrays drifted apart once already (22 vs 18), and the symptom was a Soong failure about
27# a missing prebuilt rather than anything pointing back at this script.
28BUILD_MAOS="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/build-maos.sh"
29[[ -f "$BUILD_MAOS" ]] || { echo "ERROR: cannot find $BUILD_MAOS to read the app list" >&2; exit 1; }
30mapfile -t APPS < <(sed -n 's/^APPS=(\(.*\))$/\1/p' "$BUILD_MAOS" | tr ' ' '\n' | grep -v '^$')
31[[ "${#APPS[@]}" -gt 0 ]] || { echo "ERROR: could not parse APPS=(...) from $BUILD_MAOS" >&2; exit 1; }
32
33
34find_apk() {
35 local app="$1"
36 local candidates=(
37 "$SRC/${app}-release.apk"
38 "$SRC/distribution_apks/${app}-release.apk"
39 "$SRC/${app}/build/outputs/apk/release/${app}-release.apk"
40 )
41 local c
42 for c in "${candidates[@]}"; do
43 if [[ -f "$c" ]]; then
44 printf '%s\n' "$c"
45 return 0
46 fi
47 done
48 return 1
49}
50
51missing=0
52for app in "${APPS[@]}"; do
53 if apk="$(find_apk "$app")"; then
54 cp -v "$apk" "$DEST/${app}-release.apk"
55 else
56 echo "ERROR: could not find ${app}-release.apk under $SRC" >&2
57 missing=1
58 fi
59done
60
61if [[ "$missing" -ne 0 ]]; then
62 echo "One or more APKs were missing. Build them first (Modern-Apps: ./release.sh or per-module :<app>:assembleRelease)." >&2
63 exit 1
64fi
65
66echo "Done. Copied ${#APPS[@]} APKs into $DEST"