# Multi-Machine Android Dev via Samba

## Problem

Project files live on a server (Debian), IDE runs on a workstation (Arch/CachyOS). The shared `gradle.properties` and `local.properties` encode **server-side paths** that don't exist on the client. Gradle fails with "JDK not found" or "SDK not found" on first sync.

## The Three Paths That Must Be Client-Local

### 1. `gradle.properties` → `org.gradle.java.home`

**Server path (WRONG on client):**
```properties
org.gradle.java.home=/usr/lib/jvm/java-21-openjdk-amd64    # Debian path
```

**Client path (CORRECT on Arch):**
```properties
org.gradle.java.home=/usr/lib/jvm/java-21-openjdk           # Arch path
```

**Fix:** Edit the file over the Samba mount. Java versions may differ between machines — the project's `compileOptions` must be met on both.

### 2. `local.properties` → `sdk.dir`

**Server path (WRONG on client):**
```properties
sdk.dir=/home/rurouni/Android                              # Debian SDK
```

**Client path (CORRECT):**
```properties
sdk.dir=/home/raymond/Android/Sdk                          # CachyOS SDK
```

**Fix:** Same file edit over Samba. Android Studio reads `local.properties` every sync.

### 3. `ANDROID_HOME` environment variable

Not in version control, but referenced by some scripts and CI tooling. Set per-client:

```bash
# ~/.bashrc or fish config
export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin
```

---

## JDK Switching on Arch-based Clients

If multiple JDKs are installed:

```bash
# List available JDKs
archlinux-java status

# Switch default to JDK 21
sudo archlinux-java set java-21-openjdk

# Verify
java -version   # should show 21.x
```

JDK 17 is default on many Arch installs. Project AGP 8.13+ needs JDK 21+.

---

## Gradle Cleanup After Path Changes

When switching Java/SDK paths on a Samba-shared project, the Gradle configuration cache caches the old paths:

```bash
rm -rf /mnt/<share>/.gradle/configuration-cache/
```

This forces a fresh configuration phase on next sync with the correct paths.

---

## Samba Mount Flags

Critical for Android Studio/Gradle stability:

| Flag | Purpose |
|------|---------|
| `noserverino` | Prevents inode caching issues when files change on server (Gradle file-watching) |
| `noatime` | Reduces metadata writes over network during indexing |
| `x-systemd.automount` | Lazy mount — no boot delay if server is offline; mounts on access |

**Credentials file approach** (preferred over inline password in fstab):

```ini
# /etc/fstab
//192.168.1.50/unspooled  /mnt/unspooled  cifs  credentials=/etc/smb-credentials-share,uid=1000,gid=1000,noatime,noserverino,iocharset=utf8,x-systemd.automount  0  0
```

```bash
# /etc/smb-credentials-share (mode 600)
username=rurouni
password=<samba-password>
```

---

## Key Files That Stay Server-Local (in .gitignore)

These must NOT be in version control because they encode machine-specific paths:

- `local.properties` — SDK path
- `.gradle/` — wrapper, configuration cache, build cache
- `.idea/` — IDE metadata (also includes SDK/JDK references)
- `build/` — compiled output (architecture-dependent)

Verify `.gitignore` covers these. If any are committed, they'll collide when multiple machines use the project.
