· 6 min read
Port a Bug Fix from iOS to Android with Claude: Test First
How I port a bug fix between the iOS and Android apps with a Claude agent - a behavior-only fix note, a failing test first, then a native fix.
When you fix a bug in the iOS app, the same bug often lives in the Android app too. Both apps share the same screens, the same backend and the same product rules, so they often share the same mistakes. Porting a bug fix from iOS to Android with a Claude agent sounds easy: show it the Swift diff and say "do the same in Kotlin". That prompt is the problem. The agent translates code instead of fixing behavior, and nobody checks whether the Android bug was even there. This post shows the order I use instead: a fix note in plain words, a failing test on the other platform, and only then a native fix.
This is the second post about building two native apps side by side with AI agents. The first one, iOS and Android in Parallel with Claude: One Spec, Two Apps, covers new features. Bug fixes need a slightly different flow, because a bug is a claim you have to prove before you change any code.
The example below is made up: a double tap on a "Save" button sends two requests. The method is the one I actually use.
Why "do the same in Kotlin" goes wrong
A Swift diff is the answer to an iOS question. It is shaped by SwiftUI, by async/await on the main actor and by how that repo is laid out. Hand it to an agent working in the Android repo and three things can happen:
- It ports the shape, not the reason. The agent copies a guard or a flag into a similar-looking Kotlin class, even if the Android bug comes from somewhere else.
- It "fixes" code that was fine. The Android app may never have had the bug. The agent still changes something, because you asked it to.
- Nothing proves the fix. The diff compiles and looks right. Whether the bug is gone is a guess.
So I never give the second agent the first agent's diff at the start. It gets a description of the bug instead.
Step 1: write a fix note in behavior, not code
When the iOS fix is done, I ask the iOS agent for a short fix note. It describes the bug as a user and a tester would see it. No Swift, no file names.
Bug: double tap on Save sends two update requests
## Steps
1. Open the profile edit screen.
2. Change the name.
3. Tap Save twice, quickly.
## Expected
One update request. The button is disabled while saving.
## Actual (iOS, before the fix)
Two update requests. The second one can overwrite the first.
## Root cause in plain words
The screen did not track "a save is in progress",
so every tap started a new save.
## Test that proves the fix
Two save calls in a row, with a slow API,
result in exactly one API call.
The last two sections matter most. "Root cause in plain words" lets the Android agent look for the same mistake in its own code, in its own shape. "Test that proves the fix" turns the bug into something both apps can check in the same way, in their own test frameworks.
Step 2: reproduce on the other platform first
The first task for the Android agent is not "fix the bug". It is: "Write a unit test that reproduces this bug. Run it. Tell me if it fails." No production code changes in this step.
For the made-up example, the Android test looks like this, with JUnit, MockK and kotlinx-coroutines-test:
@Test
fun `double tap on save sends one request`() = runTest {
val api = mockk<ProfileApi>()
coEvery { api.update(any()) } coAnswers { delay(100) }
val viewModel = ProfileViewModel(api, scope = this)
viewModel.onSaveClick(profile)
viewModel.onSaveClick(profile)
advanceUntilIdle()
coVerify(exactly = 1) { api.update(any()) }
}
The slow fake API is the key. With an instant fake, the first save may finish before the second tap, and the test passes even when the bug is there. runTest uses virtual time, so the delay costs nothing in real time. The kotlinx-coroutines-test docs explain how runTest and advanceUntilIdle work.
Now there are two possible results, and both are useful:
- The test fails. The bug is real on Android. Go to step 3.
- The test passes. Android never had this bug. Stop. Do not change production code. Keep the test anyway: it now guards against the bug showing up later.
The second result is the one people skip. Without a test first, the agent would have "fixed" working code, and I would have reviewed a diff that changes nothing useful.
Step 3: fix it the native way
Only after a red test does the Android agent touch production code. Its task is now narrow: "Make this test pass. Follow this repo's patterns. Do not look at the iOS code."
The iOS fix might look like this:
@MainActor
final class ProfileViewModel: ObservableObject {
@Published private(set) var isSaving = false
private let api: ProfileAPI
init(api: ProfileAPI) { self.api = api }
func save(_ profile: Profile) async {
guard !isSaving else { return }
isSaving = true
defer { isSaving = false }
try? await api.update(profile)
}
}
The Android fix follows the same idea, written the Kotlin way:
class ProfileViewModel(
private val api: ProfileApi,
private val scope: CoroutineScope,
) {
private val _isSaving = MutableStateFlow(false)
val isSaving: StateFlow<Boolean> = _isSaving
fun onSaveClick(profile: Profile) {
if (_isSaving.value) return
_isSaving.value = true
scope.launch {
try {
api.update(profile)
} finally {
_isSaving.value = false
}
}
}
}
Same rule, "one save at a time", but each side uses its own tools: the main actor and defer on iOS, a StateFlow and try/finally on Android. The Compose button then reads isSaving to disable itself. In a real app the root cause on Android may not match iOS at all. That is exactly why the agent starts from the fix note and the test, not from the Swift diff.
When the test is green, I run the full test suite and, if the bug has a UI path, the shared Maestro flow on both apps. Then I review the diff myself and merge.
The honest trade-offs
For me the pros win, but this flow has a cost.
What works well:
- Fewer pointless changes. A test that passes on the first run tells me the other app is fine, before any code is touched.
- Both apps gain a regression test. The bug is now checked on both sides, whatever the result of step 2.
- Native fixes stay native. The agent never sees the Swift code, so it does not bring Swift habits into Kotlin.
- The fix note is cheap. The first agent writes it in seconds, because it just fixed the bug and has all the context.
What costs me:
- It is slower than copying a diff. For a one-line typo in a shared string, I skip all of this.
- Some bugs are hard to reproduce in a unit test. Timing issues across threads, OS-specific behavior or UI bugs may need a Maestro flow or a manual check instead. I still write down how I checked.
- A passing test can be a bad test. If the test does not hit the real code path, "no bug on Android" is a false result. I read the test before I trust a green run.
- Review is still mine. Two agents, two repos, two diffs. The process makes my review shorter, not optional.
Takeaways
- Do not give the second agent the first agent's diff. Give it a fix note that describes the bug as behavior.
- Ask for a failing test on the other platform before any fix. A red test proves the bug exists there.
- If the test passes, stop and keep the test. Not every iOS bug is an Android bug.
- Let the agent fix the root cause in its own platform's way, with the test as the finish line.
- Read the test before you trust it. A test that misses the code path proves nothing.