11#! /usr/bin/env bash
2- # Copyright (c) 2020-2022 Collabora, Ltd.
2+ # Copyright (c) 2020-2023 Collabora, Ltd.
33#
44# SPDX-License-Identifier: Apache-2.0
55
6+ # Builds the .aar Android prefab artifact for the OpenXR Loader.
7+ # Depends on the tools `cmake`, `ninja`, and `jar` (usually shipped with your JDK)
8+ # in addition to an Android NDK.
9+ #
10+ # Requires that ANDROID_NDK_HOME be set in the environment.
11+ # Pass the argument "clean" to wipe build directories before building.
12+ #
13+ # Touch a file named SNAPSHOT in the root directory to
14+ # make a version suffixed with -SNAPSHOT
15+
616set -e
17+
18+ logMsg () {
19+ echo
20+ echo " **** $1 "
21+ echo
22+ }
23+
724ROOT=$( cd " $( dirname " $0 " ) " && cd .. && pwd)
825
926OPENXR_ANDROID_VERSION_SUFFIX=
1027if [ -f " ${ROOT} /SNAPSHOT" ]; then
1128 OPENXR_ANDROID_VERSION_SUFFIX=-SNAPSHOT
12- echo " Building a -SNAPSHOT version"
29+ logMsg " Building a -SNAPSHOT version"
1330fi
1431
1532BUILD_DIR=${BUILD_DIR:- ${ROOT} / build-android}
1633INSTALL_DIR=${INSTALL_DIR:- ${ROOT} / build-android-install}
1734
18- ANDROID_STL=$( grep ext.stl " ${ROOT} /src/loader/build.gradle " | sed -E ' s/.*"(.*)"/\1/ ' )
35+ ANDROID_STL=c++_static
1936CONFIG=Release
2037ANDROID_PLATFORM=24
2138
39+ logMsg " ANDROID_NDK_HOME: ${ANDROID_NDK_HOME} "
40+ logMsg " ANDROID_STL: ${ANDROID_STL} "
41+ logMsg " CONFIG: ${CONFIG} "
42+ logMsg " ANDROID_PLATFORM: ${ANDROID_PLATFORM} "
43+
44+ logMsg " BUILD_DIR: ${BUILD_DIR} "
45+ logMsg " INSTALL_DIR: ${INSTALL_DIR} "
46+
47+ logMsg " Wiping install staging dir"
2248rm -rf " ${INSTALL_DIR} "
49+
50+ if [ " $1 " = " clean" ]; then
51+ logMsg " Wiping build dir completely"
52+ rm -rf " ${BUILD_DIR} "
53+ fi
54+
2355if [ -d " ${BUILD_DIR} " ]; then
56+ logMsg " Removing POM files from build dir"
2457 find " ${BUILD_DIR} " -name " *.pom" -delete
2558fi
2659
2760for arch in x86 x86_64 armeabi-v7a arm64-v8a; do
61+ logMsg " Configuring and building for arch ${arch} "
2862 cmake -S " ${ROOT} " \
2963 -B " ${BUILD_DIR} /${arch} " \
3064 -G Ninja \
@@ -44,16 +78,23 @@ for arch in x86 x86_64 armeabi-v7a arm64-v8a; do
4478
4579 ninja -C " ${BUILD_DIR} /${arch} "
4680
81+ logMsg " Installing for arch ${arch} "
82+
4783 for comp in License Headers Loader Prefab; do
84+ # Component-wise install of the build, since we do not want all components
4885 cmake -DCMAKE_INSTALL_COMPONENT=${comp} -P " ${BUILD_DIR} /${arch} /cmake_install.cmake"
4986 done
5087done
88+
89+ # The name of the POM file that CMake made with our decorated version number
5190DECORATED=$( cd " ${BUILD_DIR} /x86/src/loader" && ls openxr_loader* .pom)
5291cp " ${BUILD_DIR} /x86/src/loader/${DECORATED} " .
5392
5493DIR=$( pwd)
5594(
95+ logMsg " Packing AAR file"
5696 cd " $INSTALL_DIR /openxr"
57- 7za a -r ../openxr.zip ./*
58- mv ../openxr.zip " $DIR /${DECORATED% .pom} .aar"
97+ AARFILE=" $DIR /${DECORATED% .pom} .aar"
98+ jar --create --file=" ${AARFILE} " ./*
99+ logMsg " AAR file created: ${AARFILE} "
59100)
0 commit comments