Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/android-sdk/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
"type": "string",
"default": "",
"description": "extra packages, split by space"
},
"disable_openjdk_installation": {
"type": "boolean",
"default": false,
"description": "Disables the Installation of OpenJDK by this feature."
}
},
"installsAfter": ["ghcr.io/devcontainers/features/common-utils", "ghcr.io/akhildevelops/devcontainer-features/apt"]
Expand Down
27 changes: 21 additions & 6 deletions src/android-sdk/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@ if [ -n "$EXTRA_PACKAGES" ]; then
PACKAGES=("${PACKAGES[@]}" "${extra[@]}")
fi

LINUX_PACKAGES=("unzip" "wget" "usbutils")

if [ $DISABLE_OPENJDK_INSTALLATION != "true" ]; then
LINUX_PACKAGES=("${LINUX_PACKAGES[@]}" "openjdk-17-jdk-headless")
fi

DEBIAN_FRONTEND="noninteractive" sudo apt update &&
sudo apt install --no-install-recommends -y openjdk-17-jdk-headless unzip wget usbutils &&
sudo apt install --no-install-recommends -y "${LINUX_PACKAGES[@]}" &&
apt clean

# Prepare install folder.
Expand All @@ -45,13 +51,22 @@ shopt -u dotglob

cd $ANDROID_HOME

export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin"
export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/build-tools/$BUILD_TOOLS"

# Only needed if OpenJDK is not disabled.
# checked as Java Feature installs it via sdkman causing “update-alternatives: error: no alternatives for javac”

# Save original JAVA_HOME.
OG_JAVA_HOME=$JAVA_HOME
if [ $DISABLE_OPENJDK_INSTALLATION != "true" ]; then
LINUX_PACKAGES=("${LINUX_PACKAGES[@]}" "openjdk-17-jdk-headless")

# thanks https://askubuntu.com/questions/772235/how-to-find-path-to-java#comment2258200_1029326.
export JAVA_HOME=$(dirname $(dirname $(update-alternatives --list javac 2>&1 | head -n 1)))
# Save original JAVA_HOME.
OG_JAVA_HOME=$JAVA_HOME

# thanks https://askubuntu.com/questions/772235/how-to-find-path-to-java#comment2258200_1029326.

export JAVA_HOME=$(dirname $(dirname $(update-alternatives --list javac 2>&1 | head -n 1)))

fi

# TODO: Update everything to future-proof for the link getting stale.
# yes | sdkmanager "cmdline-tools;latest"
Expand Down
10 changes: 10 additions & 0 deletions test/android-sdk/disabled_openjdk_installation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -e

source dev-container-features-test-lib

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

reportResults
10 changes: 10 additions & 0 deletions test/android-sdk/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,15 @@
"extra_packages": "ndk;25.2.9519653 sources;android-32"
}
}
},
"disabled_openjdk_installation": {
"image": "mcr.microsoft.com/devcontainers/java:dev-21-bookworm",
"features": {
"android-sdk": {
"platform": "32",
"extra_packages": "ndk;25.2.9519653 sources;android-32",
"disable_openjdk_installation": "true"
}
}
}
}
1 change: 1 addition & 0 deletions test/android-sdk/specific_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ set -e

source dev-container-features-test-lib

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

Expand Down