Skip to content

Instantly share code, notes, and snippets.

@bartekpacia
Created August 20, 2024 00:52
Show Gist options
  • Save bartekpacia/e8e086f1e46483b257d72e5c19b36250 to your computer and use it in GitHub Desktop.
Save bartekpacia/e8e086f1e46483b257d72e5c19b36250 to your computer and use it in GitHub Desktop.
Trying to automatically find the version of classfiles in Android SDK. See also: https://stackoverflow.com/q/78890085/7009800
#!/usr/bin/env bash
set -euo pipefail
for file in *.zip; do
version="$(echo "$file" | cut -d '-' -f 4 | cut -d '.' -f 1)"
new_dir="android-clt-$version"
echo "extracting file $file into $new_dir"
unzip -o -d "android-clt-$version" "$file" >/dev/null 2>&1
cd "./android-clt-$version"
# extract jar and print classfile version
rm -rf com/ META-INF/ NOTICE
if [ "$version" -ge 4 ]; then
# CLT v4 changed directory structure
tar -xf cmdline-tools/lib/common/*.jar
else
tar -xf tools/lib/common/*.jar
fi
javap -v com/android/Version.class | grep major
# clean up
rm -rf com/ META-INF/ NOTICE
cd ..
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment