Add dev container support for GitHub Codespaces

Co-authored-by: hossain-khan <99822+hossain-khan@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-30 05:05:08 +00:00
co-authored by hossain-khan
parent 4dc6a82da1
commit 5fb7fa25c2
3 changed files with 201 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
# Dev Container Configuration
This directory contains the development container configuration for TRMNL Android.
## Features
- **Base Image**: Java 17 (Bookworm)
- **Android SDK**: Manually installed via post-create script
- **Android Command Line Tools**: Version 11076708
- **Platform Tools**: Latest version
- **VS Code Extensions**: Kotlin, Gradle, Java, IntelliJ keybindings, and GitHub Copilot support
## Environment Variables
- `ANDROID_HOME`: `/usr/local/lib/android/sdk`
- `ANDROID_SDK_ROOT`: `/usr/local/lib/android/sdk`
## Post-Create Setup
The `post-create.sh` script automatically:
1. Downloads and installs Android SDK Command Line Tools if not present
2. Accepts Android SDK licenses
3. Installs Android SDK Platform 36 and Build Tools 36.0.0
4. Updates SDK components
5. Sets Gradle wrapper permissions
6. Pre-downloads Gradle dependencies
## Usage
### First Time Setup
1. Open the project in VS Code
2. When prompted, click "Reopen in Container"
3. Wait for the container to build and post-create script to complete
Alternatively, when using GitHub Codespaces:
1. Click "Code" button on the repository
2. Select "Codespaces" tab
3. Click "Create codespace on main"
### Building the Project
```bash
./gradlew assembleDebug
```
### Running Tests
```bash
./gradlew lintKotlin testDebugUnitTest --parallel --daemon
```
### Formatting Code
```bash
./gradlew formatKotlin
```
### Linting Code
```bash
./gradlew lintKotlin
```
## Connecting Android Devices
The container is configured with `--privileged` mode to allow ADB access to connected USB devices for on-device debugging. Your local `.android` directory is mounted to preserve ADB keys and settings.
## Troubleshooting
### SDK License Issues
If you encounter SDK license errors, run:
```bash
yes | sdkmanager --licenses
```
### Gradle Issues
If Gradle fails to sync, try:
```bash
./gradlew clean
./gradlew --refresh-dependencies
```
### Android SDK Not Found
Verify the environment variables:
```bash
echo $ANDROID_HOME
echo $ANDROID_SDK_ROOT
```
Both should point to `/usr/local/lib/android/sdk`.
+53
View File
@@ -0,0 +1,53 @@
{
"name": "TRMNL Android",
"image": "mcr.microsoft.com/devcontainers/java:1-17-bookworm",
"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"mathiasfrohlich.kotlin",
"fwcd.kotlin",
"vscjava.vscode-gradle",
"GitHub.copilot",
"GitHub.copilot-chat",
"redhat.java",
"vscjava.vscode-java-pack",
"k--kato.intellij-idea-keybindings"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "bash",
"java.configuration.updateBuildConfiguration": "automatic"
}
}
},
"remoteEnv": {
"ANDROID_HOME": "/usr/local/lib/android/sdk",
"ANDROID_SDK_ROOT": "/usr/local/lib/android/sdk"
},
"postCreateCommand": "bash .devcontainer/post-create.sh",
"forwardPorts": [],
"portsAttributes": {
"5037": {
"label": "ADB",
"onAutoForward": "ignore"
}
},
"mounts": [
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.android,target=/home/vscode/.android,type=bind,consistency=cached"
],
// Privileged mode is required for ADB to access USB devices for on-device debugging
"runArgs": [
"--privileged"
]
}
+54
View File
@@ -0,0 +1,54 @@
#!/bin/bash
set -e
echo "πŸš€ Setting up Android development environment..."
# Define Android SDK paths
export ANDROID_HOME="/usr/local/lib/android/sdk"
export ANDROID_SDK_ROOT="${ANDROID_HOME}"
export PATH="${PATH}:${ANDROID_HOME}/cmdline-tools/latest/bin:${ANDROID_HOME}/platform-tools"
# Install Android SDK Command Line Tools if not present
if [ ! -d "${ANDROID_HOME}/cmdline-tools" ]; then
echo "πŸ“₯ Downloading Android SDK Command Line Tools..."
# Command Line Tools version 11076708 (latest as of 2024)
# Check https://developer.android.com/studio#command-line-tools-only for newer versions
CMDLINE_TOOLS_URL="https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip"
sudo mkdir -p "${ANDROID_HOME}/cmdline-tools"
cd /tmp
wget -q "${CMDLINE_TOOLS_URL}" -O commandlinetools.zip
unzip -q commandlinetools.zip
sudo mv cmdline-tools "${ANDROID_HOME}/cmdline-tools/latest"
rm commandlinetools.zip
cd -
# Set proper ownership and permissions
sudo chown -R vscode:vscode "${ANDROID_HOME}"
sudo chmod -R 755 "${ANDROID_HOME}"
fi
# Accept Android SDK licenses
echo "πŸ“ Accepting Android SDK licenses..."
yes | sdkmanager --licenses || true
# Install required Android SDK components
echo "πŸ“¦ Installing Android SDK components..."
sdkmanager "platform-tools" "platforms;android-36" "build-tools;36.0.0" || true
# Update SDK components
echo "πŸ”„ Updating SDK components..."
sdkmanager --update || true
# Set proper permissions for Gradle wrapper
echo "πŸ”§ Setting Gradle wrapper permissions..."
chmod +x ./gradlew
# Install Gradle dependencies (helps with IDE indexing)
echo "πŸ“š Downloading Gradle dependencies..."
./gradlew --version
echo "βœ… Android development environment setup complete!"
echo "πŸ“± You can now build the project with: ./gradlew assembleDebug"
echo "πŸ§ͺ Run tests with: ./gradlew lintKotlin testDebugUnitTest"
echo "🎨 Format code with: ./gradlew formatKotlin"