Skip to content

Commit 11c01dc

Browse files
authored
feat: add android-sdk feature (#31)
* feat: add `android-sdk` feature * feat(android-sdk): add to CI test workflow
1 parent f63c18b commit 11c01dc

File tree

6 files changed

+139
-0
lines changed

6 files changed

+139
-0
lines changed

Diff for: .github/workflows/test.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
strategy:
1414
matrix:
1515
features:
16+
- android-sdk
1617
- coder
1718
- cutter
1819
- ghidra
@@ -37,6 +38,7 @@ jobs:
3738
strategy:
3839
matrix:
3940
features:
41+
- android-sdk
4042
- coder
4143
- burp-suite
4244
- cutter

Diff for: src/android-sdk/NOTES.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
> [!NOTE]
2+
> It's fine if we let `version` run out of date since it's rarely updated.
3+
> (version from "Command line tools only" section @ https://developer.android.com/studio?hl=en)

Diff for: src/android-sdk/devcontainer-feature.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "Android SDK (via Google CDN)",
3+
"id": "android-sdk",
4+
"version": "1.0.0",
5+
"description": "A feature that installs the Android command line tools and SDK",
6+
"keywords": ["android", "mobile", "mobile-development"],
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"proposals": [
11+
"11076708"
12+
],
13+
"default": "11076708",
14+
"description": "Select the Android command line tools version ('latest' is not supported)"
15+
},
16+
17+
"installMavenRepos": {
18+
"type": "boolean",
19+
"default": true,
20+
"description": "Whether or not to install the Android and Google Maven repos"
21+
},
22+
23+
"installPlayServices": {
24+
"type": "boolean",
25+
"default": true,
26+
"description": "Whether or not to install Play Services"
27+
},
28+
29+
"installEmulator": {
30+
"type": "boolean",
31+
"default": false,
32+
"description": "Whether or not to install the Android Emulator (NOTE: you still have to install the images yourself using sdkmanager)"
33+
}
34+
},
35+
36+
"containerEnv": {
37+
"ANDROID_HOME": "/usr/local/android-sdk",
38+
"ANDROID_CMDLINE_TOOLS_HOME": "${ANDROID_HOME}/cmdline-tools",
39+
"PATH": "${PATH}:${ANDROID_HOME}:${ANDROID_CMDLINE_TOOLS_HOME}/latest/bin:${ANDROID_HOME}/emulator:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools"
40+
},
41+
42+
"installsAfter": [
43+
"ghcr.io/devcontainers/features/common-utils"
44+
],
45+
46+
"dependsOn": {
47+
"ghcr.io/phorcys420/devcontainer-features/lib-common:1": {},
48+
49+
"ghcr.io/devcontainers/features/java:1": {}
50+
}
51+
}

Diff for: src/android-sdk/install.sh

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
FEATURE_NAME="android-sdk"
6+
echo "Activating feature '$FEATURE_NAME'"
7+
8+
# Source lib-common feature (DEVCONTAINER_LIBRARIES_HOME is defined by lib-common)
9+
source "$DEVCONTAINER_LIBRARIES_HOME/common/1/main.sh"
10+
11+
# Load options
12+
VERSION=${VERSION:-11076708}
13+
14+
INSTALL_MAVEN_REPOS=${INSTALL_MAVEN_REPOS:-"true"}
15+
INSTALL_PLAY_SERVICES=${INSTALL_PLAY_SERVICES:-"true"}
16+
INSTALL_EMULATOR=${INSTALL_EMULATOR:-"false"}
17+
18+
# ANDROID_HOME and ANDROID_CMDLINE_TOOLS_HOME are defined in the containerEnv value of the feature's manifest
19+
ANDROID_HOME=${ANDROID_HOME:-/usr/local/android-sdk}
20+
ANDROID_CMDLINE_TOOLS_HOME=${ANDROID_CMDLINE_TOOLS_HOME:-${ANDROID_HOME}/cmdline-tools}
21+
22+
# Check for dependencies
23+
checkPackages curl ca-certificates unzip
24+
25+
TMP=$(mktemp -d)
26+
DESTINATION_FILE="$TMP/android-sdk.zip"
27+
28+
echo "[$FEATURE_NAME] [+] Downloading version $VERSION of Android command line tools"
29+
30+
curl --get --location --silent --show-error --fail \
31+
--output "$DESTINATION_FILE" \
32+
"https://dl.google.com/android/repository/commandlinetools-linux-${VERSION}_latest.zip"
33+
34+
mkdir -p "$ANDROID_CMDLINE_TOOLS_HOME"
35+
36+
echo "[$FEATURE_NAME] [+] Extracting Android command line tools"
37+
unzip "$TMP/android-sdk.zip" -d "$ANDROID_CMDLINE_TOOLS_HOME"
38+
mv "$ANDROID_CMDLINE_TOOLS_HOME/cmdline-tools" "$ANDROID_CMDLINE_TOOLS_HOME/latest"
39+
40+
echo "[$FEATURE_NAME] [+] Accepting sdkmanager's licenses"
41+
(yes || true) | sdkmanager --licenses
42+
43+
44+
TOOLS=("tools" "platform-tools" "build-tools;34.0.0")
45+
46+
if [ "$INSTALL_MAVEN_REPOS" = "true" ]; then
47+
echo "[$FEATURE_NAME] [+] Adding Android and Google's Maven repositories to the list of tools"
48+
TOOLS+=("extras;android;m2repository" "extras;google;m2repository")
49+
fi
50+
51+
if [ "$INSTALL_PLAY_SERVICES" = "true" ]; then
52+
echo "[$FEATURE_NAME] [+] Adding play services to the list of tools"
53+
TOOLS+=("extras;google;google_play_services")
54+
fi
55+
56+
if [ "$INSTALL_EMULATOR" = "true" ]; then
57+
echo "[$FEATURE_NAME] [+] Adding the emulator to the list of tools"
58+
TOOLS+=("emulator")
59+
fi
60+
61+
echo "[$FEATURE_NAME] [+] Installing SDK tools"
62+
sdkmanager --install "${TOOLS[@]}"
63+
64+
rm -rf "$TMP"

Diff for: test/android-sdk/scenarios.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Diff for: test/android-sdk/test.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Optional: Import test library bundled with the devcontainer CLI
6+
source dev-container-features-test-lib
7+
8+
check "Android SDK folder exists" test -d "$ANDROID_HOME"
9+
10+
BINARY_LIST=("sdkmanager" "adb")
11+
12+
for binary in "${BINARY_LIST[@]}"; do
13+
check "Android SDK binary '$binary' is in the PATH" which "$binary"
14+
done
15+
16+
# Report results
17+
# If any of the checks above exited with a non-zero exit code, the test will fail.
18+
reportResults

0 commit comments

Comments
 (0)