How to Refactor Legacy Android Code with Firebender
Legacy Android code is where AI help pays off most, and where it can do the most damage. Firebender understands both old and new Android patterns, which makes it usable for migrations — if you keep the changes reviewable. This guide is the migration workflow for engineers stuck on a mature codebase.
Why migrate at all?
Because callback spaghetti and deprecated APIs slow every future feature. A screen that took a day in XML views takes hours in Compose once the pattern is set. The goal is not a big-bang rewrite; it is a steady march, one screen at a time, with the app shippable after each step.
How do you start a views-to-Compose migration?
- Pick one self-contained screen with few dependencies. Not the home screen.
- Ask Firebender to port that screen to Compose, keeping business logic untouched.
- Run the app and diff the behaviour against the old screen side by side.
- Delete the old XML once the new screen is verified and shipped.
One screen per pull request. Large migration diffs hide regressions, and reviewers stop reading.
How do you replace callbacks with coroutines?
- Migrate one repository or network layer at a time.
- Keep suspend functions at the boundary and let the agent adapt callers.
- Check dispatcher choices — IO for network and disk, Main for UI updates.
- Watch for cancellation: an old callback that ignored cancellation may now break.
The cancellation point is the one people miss. Converting threading models changes behaviour, so test the cancel path, not just the happy path.
How do you keep the build green?
Never let the agent change dependencies, code and Gradle config in the same step. Sequence them: dependency bump, then code, then config. If a step fails, revert it alone. Committing after each verified step is what makes this safe — without it, a migration branch becomes unrecoverable.
Where should you keep humans in the loop?
Anything touching payment, auth, or background scheduling. These have subtle lifecycle rules an agent may flatten. Review those diffs line by line, and keep an integration test for each migrated flow. The agent is fast; your job is to prove nothing broke.
Quick Summary
- Migrate screen by screen, never big-bang, keeping the app shippable.
- Port business logic untouched and diff behaviour against the old screen.
- Replace callbacks with coroutines layer by layer and test cancellation.
- Sequence dependency, code and config changes; commit after each verified step.
- Keep humans on payment, auth and scheduling flows with integration tests.
