# Project-Wide Android App Rename Pattern

## When to use
When renaming an Android project (app name, package, directory, branding) across 300+ Kotlin files.

## Approach: Python script + shell renames

### Phase 1: Content replacement via Python
Use a Python script that walks the entire project tree, reads text files, and applies a list of ordered replacements. **Order matters:** longer/more-specific patterns must come before shorter ones.

```python
REPLACEMENTS = [
    # Package name (most critical — affects all imports)
    ("com.oldname.app", "com.newname.app"),
    # Class names with prefixes
    ("OldPrefix", "NewPrefix"),
    # App name / branding
    ("OLD APP", "NEW APP"),
    # Lowercase variants
    ("oldname", "newname"),
]
```

### Phase 2: Directory renames
```bash
# Package directory
mv app/src/main/java/com/oldname app/src/main/java/com/newname
# Test directory
mv app/src/test/java/com/oldname app/src/test/java/com/newname
# Project directory
mv /home/user/OldProject /home/user/NewProject
```

### Phase 3: Individual file renames
Rename files that still carry old class names:
```bash
grep -rn "OldClassName" app/src/main/java/com/newname/ --include="*.kt"
mv OldClassName.kt NewClassName.kt
```

### Phase 4: Special files
- `AndroidManifest.xml`: `android:label="NEW APP"`
- `strings.xml`: app name string
- Room schemas: directory names + JSON content references
- `.idea/workspace.xml`: IDE cache
- `build.gradle.kts`: namespace/applicationId if changed

### Phase 5: Verification
```bash
# Must return zero results
grep -rn "OldName\|oldname\|OLD NAME" . --include="*.kt" --include="*.xml" --include="*.kts" --exclude-dir=build

# Must compile
./gradlew :app:compileDebugKotlin --no-configuration-cache
```

### Phase 6: Git
```bash
git init
git add -A
git commit -m "Rename branding: OldName → NewName"
git remote add origin https://github.com/user/repo.git
git push -u origin master
```

## Pitfalls
1. **Don't use sed globally** — over-matches and breaks imports in unrelated contexts. Python script with ordered replacements is safer.
2. **Don't forget Room schemas** — they contain FQCN strings that must match.
3. **Don't forget the .idea directory** — IDE cache references old names and causes confusion on reopen.
4. **Always rebuild immediately** — catch missed references before committing.
5. **Skip build directories** — Gradle caches, .gradle/, build/ contain generated files with old names that will be regenerated.
