Skip to content

Commit

Permalink
android-sdk: fix options
Browse files Browse the repository at this point in the history
add usbutils
enable custom sdkmanager packages
  • Loading branch information
hellodword authored and filiphsps committed Mar 16, 2024
1 parent 17dff13 commit 8a71d03
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/android-sdk/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
"type": "string",
"default": "34.0.0",
"description": "SDK build-tools version"
},
"base_packages": {
"type": "string",
"default": "",
"description": "packages will override default packages, split by space"
},
"extra_packages": {
"type": "string",
"default": "",
"description": "extra packages, split by space"
}
},
"installsAfter": ["ghcr.io/devcontainers/features/common-utils", "ghcr.io/akhildevelops/devcontainer-features/apt"]
Expand Down
17 changes: 12 additions & 5 deletions src/android-sdk/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ set +H
URL_SDK="https://dl.google.com/android/repository/commandlinetools-linux-10406996_latest.zip"

# Options.
PLATFORM=$platform
if [ -z "$PLATFORMS" ]; then
if [ -z "$PLATFORM" ]; then
PLATFORM="34"
fi
BUILD_TOOLS=$build_tools
if [ -z "$BUILD_TOOLS" ]; then
BUILD_TOOLS="34.0.0"
fi
if [ -n "$BASE_PACKAGES" ]; then
IFS=' ' read -ra PACKAGES <<< "$BASE_PACKAGES"
else
PACKAGES=( "platform-tools" "platforms;android-$PLATFORM" "build-tools;$BUILD_TOOLS" )
fi
if [ -n "$EXTRA_PACKAGES" ]; then
IFS=' ' read -ra extra <<< "$EXTRA_PACKAGES"
PACKAGES=("${PACKAGES[@]}" "${extra[@]}")
fi

DEBIAN_FRONTEND="noninteractive" sudo apt update &&
sudo apt install --no-install-recommends -y openjdk-17-jdk-headless unzip wget &&
sudo apt install --no-install-recommends -y openjdk-17-jdk-headless unzip wget usbutils &&
apt clean

# Prepare install folder.
Expand Down Expand Up @@ -49,7 +56,7 @@ export JAVA_HOME=$(dirname $(dirname $(update-alternatives --list javac 2>&1 | h
# TODO: Update everything to future-proof for the link getting stale.
# yes | sdkmanager "cmdline-tools;latest"
# Download the platform tools.
yes | sdkmanager "platform-tools" "platforms;android-$PLATFORM" "build-tools;$BUILD_TOOLS"
yes | sdkmanager "${PACKAGES[@]}"

# Restore JAVA_HOME.
export JAVA_HOME=$OG_JAVA_HOME
Expand Down
3 changes: 2 additions & 1 deletion test/android-sdk/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"android-sdk": {
"platform": "32"
"platform": "32",
"extra_packages": "ndk;25.2.9519653 sources;android-32"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/android-sdk/specific_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ set -e
source dev-container-features-test-lib

check "execute command" bash -c "adb --version"
check "execute command" bash -c "sdkmanager --list_installed"

reportResults
1 change: 1 addition & 0 deletions test/android-sdk/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ set -e
source dev-container-features-test-lib

check "execute command" bash -c "adb --version"
check "execute command" bash -c "sdkmanager --list_installed"

reportResults

0 comments on commit 8a71d03

Please sign in to comment.