blob: 4bdab0f73fd4b841b38fb5c1b94d80405c430dd9 [file] [log] [blame]
#!/usr/bin/env bash
#
# Copyright 2025 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Creates local.properties with a relative sdk.dir and cmake.dir to avoid invalidating Gradle configuration cache
set -euo pipefail
err() { printf "ERROR: %s\n" "$*" >&2; exit 1; }
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
SUPPORT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
REPO_ROOT="$(cd "$SUPPORT_ROOT/../.." && pwd -P)"
LOCAL_PROPERTIES="$SUPPORT_ROOT/local.properties"
detect_platform() {
case "$(uname -s | tr '[:upper:]' '[:lower:]')" in
*mingw*|*msys*|*cygwin*) echo "windows" ;;
darwin) echo "darwin" ;;
*) echo "linux" ;;
esac
}
env_sdk() {
if [[ -n "${ANDROID_HOME:-}" && -d "$ANDROID_HOME" ]]; then
printf '%s\n' "$ANDROID_HOME"; return
fi
if [[ -n "${ANDROID_SDK_ROOT:-}" && -d "$ANDROID_SDK_ROOT" ]]; then
printf '%s\n' "$ANDROID_SDK_ROOT"; return
fi
err "Set ANDROID_SDK_ROOT or ANDROID_HOME to a valid Android SDK."
}
platform="$(detect_platform)"
if [[ -d "$REPO_ROOT/prebuilts" && -d "$REPO_ROOT/frameworks/support" && "$platform" != windows ]]; then
sdk_dir="../../prebuilts/fullsdk-$platform"
cmake_dir="$sdk_dir/native-build-tools"
[[ -d "$REPO_ROOT/prebuilts/fullsdk-$platform" ]] || err "Expected SDK at: $REPO_ROOT/prebuilts/fullsdk-$platform"
else
sdk_dir="$(env_sdk)"
cmake_dir="$sdk_dir/native-build-tools"
fi
{
echo '# This file is automatically generated by development/build/write_sdk_path.sh'
echo "sdk.dir=$sdk_dir"
echo "cmake.dir=$cmake_dir"
} > "$LOCAL_PROPERTIES"