# Android Project Rename — Package, Branding, and Git

## When to use

When an Android/Kotlin project needs a full rebrand: project directory, app label, package name, class names, and all references updated.

## Process (proven on Unspooled v3.6, May 2026)

### Phase 1: Define replacement map
```python
REPLACEMENTS = [
    # Longest / most-specific first
    ("com.old.app", "com.new.app"),
    ("OldApplication", "NewApplication"),
    ("OldPlaybackService", "NewPlaybackService"),
    ("OldDatabase", "NewDatabase"),
    ("OldSidebar", "NewSidebar"),
    ("OLD_BRAND", "NEW_BRAND"),
    ("OldBrand", "NewBrand"),
    ("oldbrand", "newbrand"),
]
```

### Phase 2: Content replacement across all text files
```python
import os

root = "/path/to/project"
text_files = []
for dirpath, dirnames, filenames in os.walk(root):
    dirnames[:] = [d for d in dirnames if d not in ['.git', 'build', '.gradle', 'node_modules']]
    for f in filenames:
        if f.endswith(('.kt', '.kts', '.xml', '.properties', '.md', '.gradle')):
            text_files.append(os.path.join(dirpath, f))

for fpath in text_files:
    with open(fpath, 'r') as fh:
        content = fh.read()
    new_content = content
    for old, new in REPLACEMENTS:
        new_content = new_content.replace(old, new)
    if new_content != content:
        with open(fpath, 'w') as fh:
            fh.write(new_content)
```

### Phase 3: Rename package directories
```bash
mv app/src/main/java/com/old/app app/src/main/java/com/new/app
mv app/src/test/java/com/old/app app/src/test/java/com/new/app
```

### Phase 4: Rename class files that still have old names
Kotlin files may have old names even after content replacement. Find and rename:
```bash
find app/src/main -name "*OldName*" -exec mv {} newname \; 2>/dev/null
```

### Phase 5: Verify
```bash
# No remaining references
grep -rn "OldName\|oldname" --include="*.kt" --include="*.kts" --include="*.xml" --include="*.properties"
# Build
./gradlew :app:compileDebugKotlin --no-configuration-cache
```

### Phase 6: Room schemas
Room schema directories reference the old class name. Fix:
```bash
sed -i 's/old.package.OldDatabase/new.package.NewDatabase/g' app/schemas/old.package.OldDatabase/*.json
mv app/schemas/old.package.OldDatabase app/schemas/new.package.NewDatabase
```

## Pitfalls

- **Room schema directory names** reference the fully-qualified class with old package. Must rename both dir and JSON content.
- **.idea/workspace.xml** may still contain old names — clean with sed or delete (will regenerate).
- **build.gradle.kts** `applicationId` must match the new package.
- **strings.xml** `app_name` and **AndroidManifest.xml** `android:label` must be updated.

## Unspooled May 2026 rename stats

- Mr.VHS/NexStream → Unspooled
- `com.nexstream.app` → `com.unspooled.app`
- 337 files content-replaced
- 10+ class files renamed
- 6 Room schema directories fixed
- Build succeeded first try
