2020-10-23 17:59:08 +03:00
#!/bin/bash -e -o pipefail
2020-09-10 14:34:08 +03:00
source ~/utils/utils.sh
2020-10-05 10:57:58 +03:00
function filter_components_by_version {
minimumVersion = $1
2020-09-29 18:19:26 +03:00
shift
toolsArr =( " $@ " )
for item in ${ toolsArr [@] }
do
2020-10-05 10:57:58 +03:00
# take the last argument after spliting string by ';'' and '-''
version = $( echo " ${ item ##*[-;] } " )
if verlte $minimumVersion $version
2020-09-29 18:19:26 +03:00
then
2020-10-05 10:57:58 +03:00
components +=( $item )
2020-09-29 18:19:26 +03:00
fi
done
}
2021-02-01 12:56:44 +03:00
function get_full_ndk_version {
majorVersion = $1
ndkVersion = $( ${ SDKMANAGER } --list | grep "ndk; ${ majorVersion } .*" | awk '{gsub("ndk;", ""); print $1}' | sort -V | tail -n1)
echo " $ndkVersion "
}
2020-10-05 10:57:58 +03:00
components =()
2020-09-29 18:19:26 +03:00
ANDROID_PLATFORM =( $( get_toolset_value '.android.platform_min_version' ) )
ANDROID_BUILD_TOOL =( $( get_toolset_value '.android.build_tools_min_version' ) )
2020-09-10 14:34:08 +03:00
ANDROID_EXTRA_LIST =( $( get_toolset_value '.android."extra-list"[]' ) )
ANDROID_ADDON_LIST =( $( get_toolset_value '.android."addon-list"[]' ) )
2020-12-31 13:22:17 +05:00
ANDROID_ADDITIONAL_TOOLS =( $( get_toolset_value '.android."additional-tools"[]' ) )
2021-02-01 12:56:44 +03:00
ANDROID_NDK_MAJOR_LTS =( $( get_toolset_value '.android.ndk.lts' ) )
ANDROID_NDK_MAJOR_LATEST =( $( get_toolset_value '.android.ndk.latest' ) )
2021-07-07 15:16:23 +03:00
# Get the latest command line tools from https://developer.android.com/studio#cmdline-tools
ANDROID_OSX_SDK_URL = "https://dl.google.com/android/repository/commandlinetools-mac-7302050_latest.zip"
2020-09-10 14:34:08 +03:00
ANDROID_HOME = $HOME /Library/Android/sdk
ANDROID_OSX_SDK_FILE = tools-macosx.zip
pushd $HOME
2021-07-07 15:16:23 +03:00
echo "Downloading android command line tools..."
download_with_retries $ANDROID_OSX_SDK_URL "." $ANDROID_OSX_SDK_FILE
2020-09-10 14:34:08 +03:00
2021-07-07 15:16:23 +03:00
echo "Uncompressing android command line tools..."
2020-09-10 14:34:08 +03:00
mkdir -p $HOME /Library/Android/sdk
2021-07-07 15:16:23 +03:00
unzip -q $ANDROID_OSX_SDK_FILE -d $HOME /Library/Android/sdk/cmdline-tools
# Command line tools need to be placed in $HOME/Library/Android/sdk/cmdline-tools/latest to function properly
mv $HOME /Library/Android/sdk/cmdline-tools/cmdline-tools $HOME /Library/Android/sdk/cmdline-tools/latest
rm -f $ANDROID_OSX_SDK_FILE
2020-09-10 14:34:08 +03:00
echo ANDROID_HOME is $ANDROID_HOME
2021-07-07 15:16:23 +03:00
export PATH = $PATH :$ANDROID_HOME /cmdline-tools/latest:$ANDROID_HOME /cmdline-tools/latest/bin
2020-09-10 14:34:08 +03:00
2021-07-07 15:16:23 +03:00
SDKMANAGER = $ANDROID_HOME /cmdline-tools/latest/bin/sdkmanager
2020-09-10 14:34:08 +03:00
echo "Installing latest tools & platform tools..."
echo y | $SDKMANAGER "tools" "platform-tools"
echo "Installing latest ndk..."
2021-02-01 12:56:44 +03:00
ndkLtsLatest = $( get_full_ndk_version $ANDROID_NDK_MAJOR_LTS )
ndkLatest = $( get_full_ndk_version $ANDROID_NDK_MAJOR_LATEST )
echo y | $SDKMANAGER "ndk; $ndkLtsLatest " "ndk; $ndkLatest "
2021-01-21 11:31:14 +03:00
# This changes were added due to incompatibility with android ndk-bundle (ndk;22.0.7026061).
# Link issue virtual-environments: https://github.com/actions/virtual-environments/issues/2481
# Link issue xamarin-android: https://github.com/xamarin/xamarin-android/issues/5526
2021-02-01 12:56:44 +03:00
ln -s $ANDROID_HOME /ndk/$ndkLtsLatest $ANDROID_HOME /ndk-bundle
ANDROID_NDK_LATEST_HOME = $ANDROID_HOME /ndk/$ndkLatest
echo "export ANDROID_NDK_LATEST_HOME= $ANDROID_NDK_LATEST_HOME " >> " ${ HOME } /.bashrc"
2020-09-10 14:34:08 +03:00
2021-07-07 15:16:23 +03:00
availablePlatforms =( $( $SDKMANAGER --list | grep "platforms;android-" | cut -d"|" -f 1 | sort -u) )
2020-10-05 10:57:58 +03:00
filter_components_by_version $ANDROID_PLATFORM " ${ availablePlatforms [@] } "
2021-07-07 15:16:23 +03:00
allBuildTools =( $( $SDKMANAGER --list --include_obsolete | grep "build-tools;" | cut -d"|" -f 1 | sort -u) )
2020-10-05 10:57:58 +03:00
availableBuildTools = $( echo ${ allBuildTools [@]//*rc[0-9]/ } )
filter_components_by_version $ANDROID_BUILD_TOOL " ${ availableBuildTools [@] } "
2021-07-07 15:16:23 +03:00
echo "y" | $SDKMANAGER ${ components [@] }
2020-09-10 14:34:08 +03:00
for extra_name in " ${ ANDROID_EXTRA_LIST [@] } "
do
echo "Installing extra $extra_name ..."
echo y | $SDKMANAGER "extras; $extra_name "
done
# Intel x86 Emulator Accelerator (HAXM installer)
2021-07-14 10:02:12 +03:00
# The Android Emulator uses the built-in Hypervisor.Framework by default, and falls back to using Intel HAXM if Hypervisor.Framework fails to initialize
# https://developer.android.com/studio/run/emulator-acceleration#vm-mac
# The installation doesn't work properly on macOS Big Sur, /dev/HAX is not created
if is_Less_BigSur; then
chmod +x $ANDROID_HOME /extras/intel/Hardware_Accelerated_Execution_Manager/silent_install.sh
sudo $ANDROID_HOME /extras/intel/Hardware_Accelerated_Execution_Manager/silent_install.sh
fi
2020-09-10 14:34:08 +03:00
for addon_name in " ${ ANDROID_ADDON_LIST [@] } "
do
echo "Installing add-on $addon_name ..."
echo y | $SDKMANAGER "add-ons; $addon_name "
done
2020-12-31 13:22:17 +05:00
for tool_name in " ${ ANDROID_ADDITIONAL_TOOLS [@] } "
do
echo "Installing additional tool $tool_name ..."
echo y | $SDKMANAGER " $tool_name "
done
2020-09-10 14:34:08 +03:00
popd
echo "Installing ProGuard-5..."
PROGUARD_LOCATION = "https://github.com/Guardsquare/proguard/archive/proguard5.3.3.tar.gz"
pushd $ANDROID_HOME
cd tools
mv proguard proguard4
mkdir proguard && cd proguard
curl -L -o proguard5.tgz $PROGUARD_LOCATION
tar xzf proguard5.tgz --strip 1 && rm -f proguard5.tgz
cp ../proguard4/proguard-*.txt . # Copy the Proguard Android definitions from the previous version
popd
2020-12-17 19:37:19 +07:00
2020-12-31 13:22:17 +05:00
invoke_tests "Android"