diff --git a/images/linux/scripts/helpers/install.sh b/images/linux/scripts/helpers/install.sh index 414980bb2..bb1befe22 100644 --- a/images/linux/scripts/helpers/install.sh +++ b/images/linux/scripts/helpers/install.sh @@ -42,4 +42,9 @@ download_with_retries() { ## fi function IsPackageInstalled { dpkg -S $1 &> /dev/null +} + +verlte() { + sortedVersion=$(echo -e "$1\n$2" | sort -V | head -n1) + [ "$1" = "$sortedVersion" ] } \ No newline at end of file diff --git a/images/linux/scripts/installers/android.sh b/images/linux/scripts/installers/android.sh index 81f28ff7a..90d2013ab 100644 --- a/images/linux/scripts/installers/android.sh +++ b/images/linux/scripts/installers/android.sh @@ -8,6 +8,23 @@ set -e # Source the helpers for use with the script source $HELPER_SCRIPTS/os.sh +source $HELPER_SCRIPTS/install.sh + +function filter_components_by_version { + minimumVersion=$1 + shift + toolsArr=("$@") + + for item in ${toolsArr[@]} + do + # take the last argument after spliting string by ';'' and '-'' + version=$(echo "${item##*[-;]}") + if verlte $minimumVersion $version + then + components+=($item) + fi + done +} # Set env variable for SDK Root (https://developer.android.com/studio/command-line/variables) ANDROID_ROOT=/usr/local/lib/android @@ -42,22 +59,23 @@ else fi toolset="$INSTALLER_SCRIPT_FOLDER/toolset.json" -platforms=$(jq -r '.android.platform_list[]|"platforms;" + .' $toolset) -buildtools=$(jq -r '.android.build_tools[]|"build-tools;" + .' $toolset) +minimumBuildToolVersion=$(jq -r '.android.build_tools_min_version' $toolset) +minimumPlatformVersion=$(jq -r '.android.platform_min_version' $toolset) extras=$(jq -r '.android.extra_list[]|"extras;" + .' $toolset) addons=$(jq -r '.android.addon_list[]|"add-ons;" + .' $toolset) additional=$(jq -r '.android.additional_tools[]' $toolset) # Install the following SDKs and build tools, passing in "y" to accept licenses. -echo "y" | ${ANDROID_SDK_ROOT}/tools/bin/sdkmanager $platforms $buildtools $extras $google_api_list $addons $additional +components=( "${extras[@]}" "${addons[@]}" "${additional[@]}" ) -# Document what was added to the image +availablePlatforms=($(${ANDROID_SDK_ROOT}/tools/bin/sdkmanager --list | sed -n '/Available Packages:/,/^$/p' | grep "platforms;android-" | cut -d"|" -f 1)) +allBuildTools=($(${ANDROID_SDK_ROOT}/tools/bin/sdkmanager --list --include_obsolete | grep "build-tools;" | cut -d"|" -f 1 | sort -u)) +availableBuildTools=$(echo ${allBuildTools[@]//*rc[0-9]/}) -google_api_versions_list=$(echo "$addons"|awk -F- '/addon-google_apis-google/ {print $5}') -constraint_layout_versions_list=$(echo "$extras"|awk -F';' '/constraint-layout;/ {print $8}') -constraint_layout_solver_versions_list=$(echo "$extras"|awk -F';' '/constraint-layout-solver;/ {print $8}') -platform_versions_list=$(echo "$platforms"|awk -F- '{print $2}') -buildtools_versions_list=$(echo "$buildtools"|awk -F';' '{print $2}') +filter_components_by_version $minimumPlatformVersion "${availablePlatforms[@]}" +filter_components_by_version $minimumBuildToolVersion "${availableBuildTools[@]}" + +echo "y" | ${ANDROID_SDK_ROOT}/tools/bin/sdkmanager ${components[@]} # Add required permissions chmod -R a+rwx ${ANDROID_SDK_ROOT} diff --git a/images/linux/toolsets/toolset-1604.json b/images/linux/toolsets/toolset-1604.json index 46aad66ad..4d7bbe0e7 100644 --- a/images/linux/toolsets/toolset-1604.json +++ b/images/linux/toolsets/toolset-1604.json @@ -62,12 +62,8 @@ } ], "android": { - "platform_list": [ - "android-30", "android-29", "android-28", "android-27", "android-26", "android-25", "android-24", "android-23", "android-22", "android-21", "android-19","android-17","android-15","android-10" - ], - "build_tools": [ - "30.0.2", "30.0.1", "30.0.0", "29.0.3", "29.0.2", "29.0.0", "28.0.3", "28.0.2", "28.0.1", "28.0.0", "27.0.3", "27.0.2", "27.0.1", "27.0.0", "26.0.3", "26.0.2", "26.0.1", "26.0.0", "25.0.3", "25.0.2", "25.0.1", "25.0.0", "24.0.3", "24.0.2", "24.0.1", "24.0.0", "23.0.3", "23.0.2", "23.0.1", "22.0.1", "21.1.2", "20.0.0", "19.1.0", "17.0.0" - ], + "platform_min_version": "10", + "build_tools_min_version": "17.0.0", "extra_list": [ "android;m2repository", "google;m2repository", diff --git a/images/linux/toolsets/toolset-1804.json b/images/linux/toolsets/toolset-1804.json index 2670b4cf3..24e36c217 100644 --- a/images/linux/toolsets/toolset-1804.json +++ b/images/linux/toolsets/toolset-1804.json @@ -62,12 +62,8 @@ } ], "android": { - "platform_list": [ - "android-30", "android-29", "android-28", "android-27", "android-26", "android-25", "android-24", "android-23", "android-22", "android-21", "android-19","android-17" - ], - "build_tools": [ - "30.0.2", "30.0.1", "30.0.0", "29.0.3", "29.0.2", "29.0.0", "28.0.3", "28.0.2", "28.0.1", "28.0.0", "27.0.3", "27.0.2", "27.0.1", "27.0.0", "26.0.3", "26.0.2", "26.0.1", "26.0.0", "25.0.3", "25.0.2", "25.0.1", "25.0.0", "24.0.3", "24.0.2", "24.0.1", "24.0.0", "23.0.3", "23.0.2", "23.0.1", "22.0.1", "21.1.2", "20.0.0", "19.1.0", "17.0.0" - ], + "platform_min_version": "17", + "build_tools_min_version": "17.0.0", "extra_list": [ "android;m2repository", "google;m2repository", diff --git a/images/linux/toolsets/toolset-2004.json b/images/linux/toolsets/toolset-2004.json index 7c704263b..b4607df98 100644 --- a/images/linux/toolsets/toolset-2004.json +++ b/images/linux/toolsets/toolset-2004.json @@ -48,12 +48,8 @@ } ], "android": { - "platform_list": [ - "android-30", "android-29", "android-28", "android-27" - ], - "build_tools": [ - "30.0.2", "30.0.1", "30.0.0", "29.0.3", "29.0.2", "29.0.0", "28.0.3", "28.0.2", "28.0.1", "28.0.0", "27.0.3", "27.0.2", "27.0.1", "27.0.0" - ], + "platform_min_version": "27", + "build_tools_min_version": "27.0.0", "extra_list": [ "android;m2repository", "google;m2repository",