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
41 changes: 28 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,20 @@ jobs:
- name: Build
shell: bash
run: cargo build --release --locked --target ${{ matrix.target }}
- name: Package (Unix)
if: runner.os != 'Windows'
- name: Package (macOS app)
if: runner.os == 'macOS'
shell: bash
run: |
set -euo pipefail
app="$RUNNER_TEMP/Android CLI GUI.app"
packaging/macos/make-app.sh \
"target/${{ matrix.target }}/release/android-cli-gui" \
"$VERSION" "$app"
mkdir -p dist
ditto -c -k --sequesterRsrc --keepParent "$app" \
"dist/android-cli-gui-v${VERSION}-${{ matrix.artifact }}.zip"
- name: Package (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
set -euo pipefail
Expand Down Expand Up @@ -161,12 +173,12 @@ jobs:
steps:
- uses: actions/checkout@v7
with:
ref: ${{ needs.get-tag.outputs.commit }}
ref: ${{ github.event.repository.default_branch }}
- uses: actions/download-artifact@v8
with:
path: dist
merge-multiple: true
- name: Render formula
- name: Render cask
shell: bash
env:
VERSION: ${{ needs.get-tag.outputs.version }}
Expand All @@ -179,13 +191,13 @@ jobs:

sed \
-e "s/__VERSION__/${VERSION}/g" \
-e "s/__SHA256_MACOS_ARM64__/$(sha "android-cli-gui-v${VERSION}-aarch64-apple-darwin.tar.gz")/g" \
-e "s/__SHA256_MACOS_X86_64__/$(sha "android-cli-gui-v${VERSION}-x86_64-apple-darwin.tar.gz")/g" \
packaging/homebrew/android-cli-gui.rb.tmpl \
-e "s/__SHA256_MACOS_ARM64__/$(sha "android-cli-gui-v${VERSION}-macos-arm64.zip")/g" \
-e "s/__SHA256_MACOS_X86_64__/$(sha "android-cli-gui-v${VERSION}-macos-x86_64.zip")/g" \
packaging/homebrew/android-cli-gui.cask.rb.tmpl \
> dist/android-cli-gui.rb

ruby -c dist/android-cli-gui.rb
- name: Push formula to tap
- name: Push cask to tap
shell: bash
env:
TAG: ${{ needs.get-tag.outputs.tag }}
Expand All @@ -202,16 +214,19 @@ jobs:

rm -rf tap
git clone --depth 1 git@github.com:RayhanHamada/homebrew-tap.git tap
mkdir -p tap/Formula
cp dist/android-cli-gui.rb tap/Formula/android-cli-gui.rb
mkdir -p tap/Casks
cp dist/android-cli-gui.rb tap/Casks/android-cli-gui.rb
if [[ -f tap/Formula/android-cli-gui.rb ]]; then
git -C tap rm Formula/android-cli-gui.rb
fi

git -C tap config user.name "github-actions[bot]"
git -C tap config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C tap add Formula/android-cli-gui.rb
git -C tap add Casks/android-cli-gui.rb

if git -C tap diff --cached --quiet; then
echo "Formula is already up to date."
echo "Cask is already up to date."
else
git -C tap commit -m "android-cli-gui ${TAG}"
git -C tap commit -m "android-cli-gui ${TAG} (cask)"
git -C tap push origin HEAD:main
fi
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,31 @@ comes from the official Android CLI and Android SDK sources.

## Install

Homebrew (macOS 15+):
Homebrew cask (macOS 15+):

```sh
brew install RayhanHamada/tap/android-cli-gui
brew tap RayhanHamada/tap
brew trust --cask RayhanHamada/tap/android-cli-gui
brew install --cask RayhanHamada/tap/android-cli-gui
```

Prebuilt binaries for Linux, macOS (Apple Silicon and Intel), and Windows are on the
[releases page](https://github.com/RayhanHamada/android-cli-gui/releases).
This installs `Android CLI GUI.app` in `/Applications` and the official
[`android-cli`](https://developer.android.com/tools/agents/android-cli) cask as
a dependency. Launch it from Applications, Launchpad, or Spotlight like any
other Mac app.

Homebrew 7 requires trusting third-party casks before installation. On older
Homebrew versions the `brew trust` step can be skipped.

If you installed the old formula, remove it before switching:

The official `android` CLI must be installed and available on `PATH`.
```sh
brew uninstall android-cli-gui
```

Prebuilt applications for macOS (Apple Silicon and Intel), binaries for Linux
and Windows, and checksums are on the
[releases page](https://github.com/RayhanHamada/android-cli-gui/releases).

## Build from source

Expand All @@ -27,9 +42,20 @@ Requires Rust stable and the [GPUI platform dependencies](https://gpui-kit.com/d
cargo run --release
```

To build a macOS app bundle:

```sh
cargo build --release
version="$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml)"
packaging/macos/make-app.sh target/release/android-cli-gui "$version" \
"target/Android CLI GUI.app"
open "target/Android CLI GUI.app"
```

## Releases

Releases are managed by [Knope Bot](https://knope.tech/tutorials/bot-workflow/).
Install the bot for this repository; it keeps a `knope/release` PR up to date.
Merging that PR creates a draft GitHub release, and the Release workflow builds
the binaries, uploads them, publishes the release, and updates the Homebrew tap.
the packages, uploads them, publishes the release, and updates the Homebrew
cask in the tap.
27 changes: 27 additions & 0 deletions packaging/homebrew/android-cli-gui.cask.rb.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
cask "android-cli-gui" do
arch arm: "macos-arm64", intel: "macos-x86_64"

version "__VERSION__"
sha256 arm: "__SHA256_MACOS_ARM64__",
intel: "__SHA256_MACOS_X86_64__"

url "https://github.com/RayhanHamada/android-cli-gui/releases/download/v#{version}/android-cli-gui-v#{version}-#{arch}.zip"
name "Android CLI GUI"
desc "Unofficial GUI for the official Android CLI"
homepage "https://github.com/RayhanHamada/android-cli-gui"

depends_on cask: "android-cli"
depends_on macos: :sequoia

app "Android CLI GUI.app"

uninstall quit: "io.github.rayhanhamada.android-cli-gui"

zap trash: [
"~/Library/Application Support/io.github.rayhanhamada.android-cli-gui",
"~/Library/Caches/io.github.rayhanhamada.android-cli-gui",
"~/Library/Saved Application State/io.github.rayhanhamada.android-cli-gui.savedState",
]

caveats "If macOS blocks the first launch, open System Settings > Privacy & Security and choose Open Anyway."
end
24 changes: 0 additions & 24 deletions packaging/homebrew/android-cli-gui.rb.tmpl

This file was deleted.

Binary file added packaging/macos/AppIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions packaging/macos/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Android CLI GUI</string>
<key>CFBundleExecutable</key>
<string>android-cli-gui</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleIdentifier</key>
<string>io.github.rayhanhamada.android-cli-gui</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Android CLI GUI</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>__VERSION__</string>
<key>CFBundleVersion</key>
<string>__VERSION__</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSMinimumSystemVersion</key>
<string>15.0</string>
<key>NSHighResolutionCapable</key>
<true/>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsAutomaticGraphicsSwitching</key>
<true/>
</dict>
</plist>
59 changes: 59 additions & 0 deletions packaging/macos/make-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash
# Assemble a launchable macOS .app bundle around the release binary.
#
# Usage: make-app.sh <binary> <version> <output.app>
set -euo pipefail

if [[ $# -ne 3 ]]; then
echo "usage: $0 <binary> <version> <output.app>" >&2
exit 2
fi

binary=$1
version=$2
app=$3

if [[ "$(uname -s)" != "Darwin" ]]; then
echo "make-app.sh requires macOS (sips, iconutil, codesign)." >&2
exit 1
fi
if [[ ! -x "$binary" ]]; then
echo "Binary not found or not executable: $binary" >&2
exit 1
fi
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version must be a semantic version, got: $version" >&2
exit 1
fi

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
contents="$app/Contents"
resources="$contents/Resources"

rm -rf "$app"
mkdir -p "$contents/MacOS" "$resources"

install -m 755 "$binary" "$contents/MacOS/android-cli-gui"
sed "s/__VERSION__/$version/g" "$script_dir/Info.plist" > "$contents/Info.plist"
printf 'APPL????' > "$contents/PkgInfo"

iconset="$(mktemp -d)/AppIcon.iconset"
mkdir -p "$iconset"
trap 'rm -rf "$(dirname "$iconset")"' EXIT
for size in 16 32 128 256 512; do
sips -z "$size" "$size" "$script_dir/AppIcon.png" \
--out "$iconset/icon_${size}x${size}.png" >/dev/null
sips -z "$((size * 2))" "$((size * 2))" "$script_dir/AppIcon.png" \
--out "$iconset/icon_${size}x${size}@2x.png" >/dev/null
done
iconutil -c icns "$iconset" -o "$resources/AppIcon.icns"

plutil -lint "$contents/Info.plist" >/dev/null

# Ad-hoc signing keeps the bundle self-consistent on Apple Silicon. Homebrew
# downloads do not carry a browser quarantine flag, so no notarization is
# required for cask installs.
codesign --force --deep --sign - "$app" >/dev/null
codesign --verify --deep --strict "$app"

echo "Built $app"
77 changes: 74 additions & 3 deletions src/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,59 @@ pub fn cli_binary_name() -> &'static str {
}
}

/// Find the official Android CLI on `PATH`.
/// Find the official Android CLI on `PATH` or in a standard install location.
///
/// macOS apps launched from Finder inherit launchd's minimal `PATH`, not the
/// login shell's. Homebrew installs the CLI at `/opt/homebrew/bin` (Apple
/// Silicon) or `/usr/local/bin` (Intel), so check those too.
pub fn find_cli() -> Option<PathBuf> {
let name = cli_binary_name();
let path_var = env::var_os("PATH")?;
env::split_paths(&path_var)
search_paths()
.into_iter()
.map(|dir| dir.join(name))
.find(|path| is_executable(path))
}

fn search_paths() -> Vec<PathBuf> {
search_paths_from(env::var_os("PATH").as_deref())
}

fn search_paths_from(path_var: Option<&std::ffi::OsStr>) -> Vec<PathBuf> {
let mut paths: Vec<PathBuf> = path_var
.map(env::split_paths)
.into_iter()
.flatten()
.filter(|dir| !dir.as_os_str().is_empty())
.collect();

#[cfg(target_os = "macos")]
let extra = ["/opt/homebrew/bin", "/usr/local/bin"];
#[cfg(not(target_os = "macos"))]
let extra = ["/usr/local/bin"];

for dir in extra {
let dir = PathBuf::from(dir);
if !paths.contains(&dir) {
paths.push(dir);
}
}

if let Some(home) = env::var_os("HOME") {
let dir = PathBuf::from(home).join(".local/bin");
if !paths.contains(&dir) {
paths.push(dir);
}
}

paths
}

/// PATH for child `android` processes. Android tooling invokes helpers such as
/// `java` and `adb`, so the GUI must hand them the same expanded PATH.
fn child_path() -> std::ffi::OsString {
env::join_paths(search_paths()).unwrap_or_else(|_| env::var_os("PATH").unwrap_or_default())
}

#[cfg(unix)]
fn is_executable(path: &std::path::Path) -> bool {
use std::os::unix::fs::PermissionsExt;
Expand Down Expand Up @@ -387,6 +431,7 @@ fn run(
running: &RunningCli,
) -> Result<String, String> {
let mut command = Command::new(bin);
command.env("PATH", child_path());
if let Some(root) = root {
command.arg(format!("--sdk={}", root.display()));
}
Expand Down Expand Up @@ -594,6 +639,32 @@ Available packages:
assert!(started.elapsed() < Duration::from_secs(2));
}

#[test]
fn search_paths_fall_back_to_standard_bin_dirs() {
let path_var = env::join_paths([PathBuf::from("/usr/bin"), PathBuf::from("/bin")]).unwrap();
let paths = search_paths_from(Some(&path_var));

assert_eq!(paths[0], PathBuf::from("/usr/bin"));
assert!(paths.contains(&PathBuf::from("/usr/local/bin")));
#[cfg(target_os = "macos")]
assert!(paths.contains(&PathBuf::from("/opt/homebrew/bin")));
}

#[test]
fn search_paths_do_not_duplicate_existing_dirs() {
let path_var =
env::join_paths([PathBuf::from("/usr/local/bin"), PathBuf::from("/usr/bin")]).unwrap();
let paths = search_paths_from(Some(&path_var));

assert_eq!(
paths
.iter()
.filter(|path| *path == &PathBuf::from("/usr/local/bin"))
.count(),
1
);
}

#[cfg(unix)]
#[test]
fn only_executable_files_count_as_cli() {
Expand Down
Loading
Loading