1+ #! /usr/bin/env bash
2+ #
3+ # Copyright 2025 The Android Open Source Project
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # https://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+ #
17+
18+ # IGNORE this file, it's only used in the internal Google release process
19+ # Fail on any error to ensure the script stops if a step fails.
20+ set -e
21+
22+ # --- Configuration ---
23+ # Get the script's directory.
24+ DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
25+ echo DIR
26+ # Define the Android SDK version you want to target.
27+ ANDROID_SDK_VERSION=" 36"
28+ ANDROID_BUILD_TOOLS_VERSION=" 36.0.0"
29+
30+ # Switched from 'google_apis' to 'google_atd' (Google Automated Test Device).
31+ # This system image is designed for headless, automated testing in CI environments
32+ # and is more compatible with software rendering. It will be installed but may not
33+ # be used by the new build command.
34+ # 36 not available yet as per b/432143095
35+ EMULATOR_IMAGE=" system-images;android-35;google_atd;x86_64"
36+
37+ # --- Environment Setup ---
38+
39+ # Step 1: Check for essential command-line tools.
40+ echo " INFO: Checking for prerequisites (wget, unzip, tar)..."
41+ for cmd in wget unzip tar; do
42+ if ! command -v $cmd & > /dev/null; then
43+ echo " ERROR: Command '$cmd ' not found. Please install it using your system's package manager (e.g., 'sudo apt-get install $cmd ') and try again."
44+ exit 1
45+ fi
46+ done
47+ echo " INFO: Prerequisites are installed."
48+
49+
50+ # Step 2: Install and configure Java 17 system-wide.
51+ echo " INFO: Setting up Java 17..."
52+ # The build needs Java 17, set it as the default Java version.
53+ sudo apt-get update
54+ sudo apt-get install -y openjdk-17-jdk
55+ sudo update-alternatives --set java /usr/lib/jvm/java-17-openjdk-amd64/bin/java
56+ java -version
57+
58+ # Also clear JAVA_HOME variable so java -version is used instead
59+ export JAVA_HOME=
60+
61+ # Add the local SDK and emulator tools to the PATH for this session.
62+ # The system-wide Java will already be in the PATH.
63+ export PATH=" $PATH :$ANDROID_HOME /cmdline-tools/latest/bin:$ANDROID_HOME /platform-tools:$ANDROID_HOME /emulator"
64+ echo " INFO: Local tools added to PATH."
65+
66+ # Now, accept licenses and install packages.
67+ # It's best practice to accept licenses *after* the tools are in place.
68+ echo " INFO: Accepting all pending SDK licenses..."
69+ yes | sdkmanager --licenses
70+
71+ echo " INFO: Installing Android SDK packages, including emulator and system image..."
72+ # This single command will install/update all necessary packages.
73+ sdkmanager " platforms;android-${ANDROID_SDK_VERSION} " " build-tools;${ANDROID_BUILD_TOOLS_VERSION} " " platform-tools" " ${EMULATOR_IMAGE} " " emulator"
74+
75+ # Run license acceptance AGAIN after installing new packages. This is crucial.
76+ echo " INFO: Accepting licenses for newly installed packages..."
77+ yes | sdkmanager --licenses
78+
79+ echo " Copying google-services.json"
80+ cp /tmpfs/src/git/androidify-prebuilts/google-services.json ${DIR} /app
81+
82+ echo " Copying gradle.properties"
83+ echo " " >> ${DIR} /gradle.properties # add a new line to the file
84+ cat /tmpfs/src/git/androidify-prebuilts/gradle.properties >> ${DIR} /gradle.properties
85+ ls
86+
87+ # --- Build Process ---
88+
89+ # This script assembles the release build of the Android application.
90+ # Ensure gradlew is executable
91+ chmod +x ./gradlew
92+
93+ # Clean the project (optional, but good for a fresh release build)
94+ echo " INFO: Cleaning the project..."
95+ ./gradlew clean -Pandroid.sdk.path=$ANDROID_HOME
96+
97+ echo " INFO: Building the Wear OS production release bundle..."
98+ ./gradlew wear:bundleRelease -x test -x uploadCrashlyticsMappingFileRelease -Pandroid.sdk.path=$ANDROID_HOME -PCI_BUILD=true
99+
100+ # --- Artifact Collection ---
101+ echo " INFO: Preparing artifacts for Kokoro..."
102+
103+ # This function collects a specific AAB and its associated in-toto files.
104+ # Arguments:
105+ # $1: Source directory for the AAB (e.g., "app/build/outputs/bundle/release")
106+ # $2: Source filename for the AAB (e.g., "app-release.aab")
107+ # $3: Destination filename for the AAB (e.g., "app-release-unsigned.aab")
108+ collect_artifacts () {
109+ local aab_src_dir=" $1 "
110+ local aab_file=" $2 "
111+ local aab_dest_file=" $3 "
112+ local aab_path=" ${aab_src_dir} /${aab_file} "
113+
114+ # Check if the AAB exists
115+ if [[ -f " $aab_path " ]]; then
116+ # Create a directory within Kokoro's artifact collection area
117+ local artifact_dest_dir=" ${KOKORO_ARTIFACTS_DIR} /artifacts"
118+ mkdir -p " ${artifact_dest_dir} "
119+
120+ # Copy the AAB
121+ cp " ${aab_path} " " ${artifact_dest_dir} /${aab_dest_file} "
122+ echo " SUCCESS: AAB copied to ${artifact_dest_dir} "
123+
124+
125+ else
126+ echo " FAILURE: AAB not found at ${aab_path} "
127+ exit 1
128+ fi
129+ }
130+
131+ # Copy the app-specific SPDX SBOM
132+ echo " INFO: Copying SPDX SBOM..."
133+ cp app/build/spdx/release.spdx.json " ${KOKORO_ARTIFACTS_DIR} /artifacts/wear-release.spdx.json"
134+
135+ # Collect the Wear OS application artifacts
136+ collect_artifacts " wear/build/outputs/bundle/release" " wear-release.aab" " wear-release-unsigned.aab"
137+
138+ exit 0
0 commit comments