I was trying to make a bash script to automatically install flutter and android sdk without Android Studio.
I managed to get the latest version of build-tools using the following sequence
btversion=`sdkmanager --list | tac | sed "/build-tools/q" | tac | sed -n 1p`
btversion=${btversion% *}
btversion=${btversion:2}
I am trying to do something similar to install platforms;android-%version%
, except doing something like this lead me to a dead end:
sdkmanager --list | tac | sed "/platforms;android-[0-9] /g"
The [0-9]
filter is necessary as packages such as platforms;android-TiramisuPrivacySandbox
show up in the list.
I would like to know what would be a better filter. For reference, this is how the output of sdkmanager --list sort of looks like
platforms;android-27 | 3 | Android SDK Platform 27
platforms;android-28 | 6 | Android SDK Platform 28
platforms;android-29 | 5 | Android SDK Platform 29
platforms;android-30 | 3 | Android SDK Platform 30
platforms;android-31 | 1 | Android SDK Platform 31
platforms;android-32 | 1 | Android SDK Platform 32
platforms;android-33 | 2 | Android SDK Platform 33
CodePudding user response:
It would be like
sdkmanager --list | egrep -i 'platforms;android-[0-9]{2}' | tac | head -n 1 | sed 's/\(platforms;android-[0-9]\ \).*/\1/'
or
sdkmanager --list | egrep -i 'platforms;android-[0-9]{2}' | sed 's/\(platforms;android-[0-9]\ \).*/\1/' | tail -1