Skip to content
Merged
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
33 changes: 4 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g. v5.4)'
description: 'Release version (e.g. v6.0)'
required: true
type: string

Expand All @@ -23,16 +23,15 @@ jobs:
- name: Validate version format
run: |
if [[ ! "${{ github.event.inputs.version }}" =~ ^v[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format. Expected format: v<major>.<minor> (e.g. v5.4)"
echo "Invalid version format. Expected format: v<major>.<minor> (e.g. v6.0)"
exit 1
fi

- name: Create and push tags
- name: Create or update release tag
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const version = '${{ github.event.inputs.version }}';
const major = version.split('.')[0]; // e.g. "v5"

const { data: ref } = await github.rest.git.getRef({
owner: context.repo.owner,
Expand All @@ -42,7 +41,7 @@ jobs:
const sha = ref.object.sha;
console.log(`main branch SHA: ${sha}`);

// Create or update the full version tag (e.g. v5.4)
// Create or update the release tag (e.g. v6.0)
try {
await github.rest.git.createRef({
owner: context.repo.owner,
Expand All @@ -66,30 +65,6 @@ jobs:
}
}

// Create or force-update the major version tag (e.g. v5)
try {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${major}`,
sha,
});
console.log(`Created tag ${major}`);
} catch (e) {
if (e.status === 422) {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${major}`,
sha,
force: true,
});
console.log(`Updated tag ${major}`);
} else {
throw e;
}
}

- name: Create GitHub Release
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
Expand Down
32 changes: 17 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ jobs:
cache-disabled: false
sdk-version: ${{ matrix.sdk }}
build-tools-version: 36.0.0
cmake-version: 3.10.2.4988404
ndk-version: 25.1.8937393
cmake-version: 3.31.6
ndk-version: 28.2.13676358

- run: |
./sample-android-project/gradlew -p sample-android-project assembleDebug --stacktrace
Expand Down Expand Up @@ -86,10 +86,10 @@ jobs:
uses: ./
with:
cache-disabled: true
sdk-version: 36
sdk-version: "37.0"
build-tools-version: 36.0.0
cmake-version: 3.10.2.4988404
ndk-version: 25.1.8937393
cmake-version: 3.31.6
ndk-version: 28.2.13676358

- run: |
./sample-android-project/gradlew -p sample-android-project assembleDebug --stacktrace
Expand Down Expand Up @@ -177,8 +177,8 @@ jobs:
- run: |
sdkmanager --list_installed | grep "platforms;android-37.0"

test_removed_codename_sdk_version_error:
name: run test removed codename sdk version error
test_unavailable_codename_sdk_version_error:
name: run test unavailable codename sdk version error
runs-on: ubuntu-latest
timeout-minutes: 20

Expand All @@ -193,20 +193,22 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Verify removed codename SDK version error
- name: Verify unavailable codename SDK version error
shell: bash
run: |
set +e
env \
'INPUT_SDK-VERSION=CinnamonBun' \
'INPUT_SDK-VERSION=UnavailableCodenameForTest' \
'INPUT_CACHE-DISABLED=true' \
'INPUT_COMMAND-LINE-TOOLS-VERSION=14742923' \
'INPUT_COMMAND-LINE-TOOLS-VERSION=15859902' \
node dist/setup/index.js 2>&1 | tee "$RUNNER_TEMP/setup-android.log"
status=${PIPESTATUS[0]}
set -e

test "$status" -ne 0
grep -F 'codename-based Android SDK platform "platforms;android-CinnamonBun"' \
grep -F 'codename-based Android SDK platform "platforms;android-UnavailableCodenameForTest"' \
"$RUNNER_TEMP/setup-android.log"
grep -F 'Codename values are supported when their exact package IDs are published' \
"$RUNNER_TEMP/setup-android.log"

test_custom_cache_key:
Expand Down Expand Up @@ -287,8 +289,8 @@ jobs:
uses: ./
with:
sdk-version: |
35
36
37.0

- run: |
sdkmanager --list_installed
Expand Down Expand Up @@ -387,7 +389,7 @@ jobs:
run: |
test "$(node -p process.arch)" = "$EXPECTED_NODE_ARCHITECTURE"
env \
'INPUT_SDK-VERSION=36' \
'INPUT_SDK-VERSION=37.0' \
'INPUT_CACHE-DISABLED=true' \
'INPUT_COMMAND-LINE-TOOLS-VERSION=15859902' \
node dist/setup/index.js 2>&1 | tee "$RUNNER_TEMP/setup-android.log"
Expand Down Expand Up @@ -434,9 +436,9 @@ jobs:
uses: ./
with:
build-tools-version: |
30.0.3
31.0.0
34.0.0
35.0.0
36.0.0

- run: |
sdkmanager --list_installed
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2025 amyu and contributors
Copyright (c) 2022-2026 amyu and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
117 changes: 61 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
# setup-android

This action provides the following functionality for GitHub Actions users:
`setup-android` installs Android SDK components on self-hosted GitHub Actions runners.

- Optionally downloading and caching distribution of the requested sdk version or build tools version or ndk,cmake version.
- Runs on Mac, Linux and Windows powered by SelfHostedRunner.
- Exporting environment variables:
- Downloads the Android command-line tools for Linux, macOS, and Windows.
- Installs requested Android SDK platforms and optional Build Tools, NDK, and CMake versions.
- Optionally caches the installed Android SDK.
- Exports the following environment variables:
+ `ANDROID_SDK_ROOT`
+ `ANDROID_HOME`
+ `ANDROID_NDK_ROOT` (when `ndk-version` is specified)
+ `ANDROID_NDK_HOME` (when `ndk-version` is specified)
+ `ANDROID_NDK` (when `ndk-version` is specified)
+ `CMAKE_VERSION` (when `cmake-version` is specified)
- Adding to PATH:
- Adds the following directories to `PATH`:
+ `$ANDROID_SDK_ROOT/platform-tools`
+ `$ANDROID_SDK_ROOT/ndk-bundle`
+ `$ANDROID_SDK_ROOT/cmdline-tools/latest/bin`
+ `$ANDROID_SDK_ROOT/ndk/<version>` (when `ndk-version` is specified)

# Motivation
## When to use this action

This Action is provided for SelfHostedRunner.
GithubHostedRunner does not need this Action as it already has the SDK set up.
GitHub-hosted runners already include the Android SDK. This action is primarily
intended for self-hosted runners or jobs that require a clean, customized SDK
installation.

# Usage
## Usage

See [action.yml](action.yml)
See [action.yml](action.yml) for the complete input reference.

**Basic:**
### Basic usage

```yaml
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup JDK 17
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0
uses: actions/setup-java@03ad4de0992f5dab5e18fcb136590ce7c4a0ac95 # v5.6.0
with:
java-version: 17
distribution: jetbrains
Expand All @@ -42,93 +44,96 @@ steps:
- run: ./gradlew build --stacktrace
```

**Recommend:**
### Read the SDK version from a version catalog

If your project uses VersionCatalog, the following settings are recommended
If your project uses a Gradle version catalog, the SDK version can be passed to
the action dynamically:

```yaml
- name: "Get sdkVersion from versions.toml"
id: read_version
shell: bash
run: |
version=`perl -nlE 'say if s/compileSdkVersion \= \"(.*)\"/$1/g' gradle/libs.versions.toml`
echo "sdkVersion=$version" >> $GITHUB_OUTPUT
version=$(perl -nlE 'say if s/compileSdkVersion \= \"(.*)\"/$1/g' gradle/libs.versions.toml)
echo "sdkVersion=$version" >> "$GITHUB_OUTPUT"

- name: Setup Android SDK
uses: amyu/setup-android@3fe49086b1abd7c9ef865120d5d4d486fe55ba98 # v5.7
with:
sdk-version: ${{ steps.read_version.outputs.sdkVersion }}
```

**More Information:**
### Configuration examples

```yaml
- name: Setup Android SDK
uses: amyu/setup-android@3fe49086b1abd7c9ef865120d5d4d486fe55ba98 # v5.7
with:
# default: false
# Whether to use the cache
cache-disabled: true
# Disable Android SDK caching.
cache-disabled: false

# default: `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-${commandLineToolsVersion}-${hashedCacheDirectory}-v5`
# Custom key for cache. It is invalid when `cache-disabled: true`
# default: `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-${commandLineToolsVersion}-${hashedCacheDirectory}-v6`
# Custom cache key. Ignored when `cache-disabled` is true.
cache-key: 'custom-cache-key'

# default: 36
# sdk version. Supports major and major.minor API levels.
# see https://developer.android.com/studio/releases/platforms
# default: 37.0
# Android SDK platform suffix. Supports major, major.minor, and published
# codename-based values.
# See https://developer.android.com/studio/releases/platforms
# API level 37 and later use minor versions in SDK Manager. A bare major
# version such as 37 is installed as 37.0 with a warning.
# It will always be installed.
sdk-version: 36
# or
sdk-version: 37.0
# or
sdk-version: "37.0"
# Install multiple SDK platforms.
sdk-version: |
35
36
# or set sdk-version to a codename-based platform package from SDK Manager
sdk-version: CinnamonBun
37.0

# default: ''
# build tools version
# see https://developer.android.com/studio/releases/build-tools
# Optional. If omitted, this action does not preinstall build-tools.
# In typical Android/Gradle projects, prefer letting AGP manage the required version.
# Set this only when you need to preinstall a specific version in CI.
# Android SDK Build Tools version. If omitted, Build Tools are not
# preinstalled. Prefer letting AGP select the required version unless a
# specific version must be available in CI.
# See https://developer.android.com/studio/releases/build-tools
build-tools-version: 36.0.0
# or
# Install multiple Build Tools versions.
build-tools-version: |
30.0.3
31.0.0
35.0.0
36.0.0

# default: ''
# cmake version
# see https://developer.android.com/studio/projects/install-ndk
# Installed when the version is specified
cmake-version: 3.10.2.4988404
# CMake version to install.
# See https://developer.android.com/studio/projects/install-ndk
cmake-version: 3.31.6

# default: ''
# cmake version
# see https://developer.android.com/studio/projects/install-ndk
# Installed when the version is specified
ndk-version: 23.1.7779620
# Android NDK version to install.
# See https://developer.android.com/ndk/downloads
ndk-version: 28.2.13676358

# default: 15859902
# see https://developer.android.com/studio#command-tools
# ex commandlinetools-mac_arm64-${command-line-tools-version}_latest.zip
# Android command-line tools package revision.
# See https://developer.android.com/studio#command-line-tools-only
command-line-tools-version: 15859902

# default: true
# Whether to generate or not the job summary
# Generate a job summary.
generate-job-summary: false
```

# License
### Codename-based preview platforms

The scripts and documentation in this project are released under the [MIT License](LICENSE)
Codename-based SDK platforms are supported when they are published in Google's
SDK repository. Pass the exact suffix shown after `platforms;android-` by
[`sdkmanager --list`](https://developer.android.com/tools/sdkmanager#list_installed_and_available_packages).
For example, a package named
`platforms;android-<codename>` is selected with `sdk-version: <codename>`.
Availability depends on the current SDK repository; when no codename package is
listed, use an available numeric platform suffix instead.

# Contributions
## License

The scripts and documentation in this project are released under the [MIT License](LICENSE).

## Contributing

Contributions are welcome!
Loading
Loading