<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Prikshit</title>
    <description>The latest articles on DEV Community by Prikshit (@prikshit).</description>
    <link>https://dev.to/prikshit</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4248247%2F6f30bf1a-0f2c-4cd4-8862-e6b6506c6914.jpg</url>
      <title>DEV Community: Prikshit</title>
      <link>https://dev.to/prikshit</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prikshit"/>
    <language>en</language>
    <item>
      <title>The Tests Pass. Does the New Kotlin Code Behave Like the Old Java?</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Thu, 03 Dec 2026 18:02:01 +0000</pubDate>
      <link>https://dev.to/prikshit/the-tests-pass-does-the-new-kotlin-code-behave-like-the-old-java-1m53</link>
      <guid>https://dev.to/prikshit/the-tests-pass-does-the-new-kotlin-code-behave-like-the-old-java-1m53</guid>
      <description>&lt;p&gt;&lt;em&gt;How to Prove an AI-Written Migration Is Correct: Shadow Runs, Diffs and Staged Rollouts&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A week to write, a lot longer to trust
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhv2ij9vemhsxjbw6tu3m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhv2ij9vemhsxjbw6tu3m.png" alt="Headline &amp;quot;A week to write, a lot longer to trust&amp;quot; with trust highlighted in a green pill. Body text: &amp;quot;Claude wrote core API code in about a week, but verification, not generation, became the bottleneck.&amp;quot; A cyan calendar card says &amp;quot;Write 1 week&amp;quot; with a check mark. A green calendar card says &amp;quot;Trust Much longer&amp;quot; with a clock. A laptop showing code sits behind a green shield with a check mark." width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On 25 November, Anthropic &lt;a href="https://www.anthropic.com/research/migrating-api-to-rust" rel="noopener noreferrer"&gt;published a write-up&lt;/a&gt; about migrating its Messages API from Python to Rust.&lt;/p&gt;

&lt;p&gt;The Rust API uses "about 70% less CPU per request" and "cuts median time to first token by about 20%". They completed the migration "without ever taking the service offline or freezing feature development."&lt;/p&gt;

&lt;p&gt;There are some limitations to these numbers. The CPU figure comes from one region, while the time to first token figure covers Claude Code requests over a shorter period.&lt;/p&gt;

&lt;p&gt;One thing I found interesting in the article was how quickly Claude wrote the initial implementation.&lt;/p&gt;

&lt;p&gt;"Claude wrote a first version of the API's core request path in about a week."&lt;/p&gt;

&lt;p&gt;Most of the article explains why writing that initial implementation was the easier part. Anthropic describes the problem in one sentence:&lt;/p&gt;

&lt;p&gt;"Verification, not generation, had become the bottleneck."&lt;/p&gt;

&lt;p&gt;An AI assistant might be able to convert a module from Java to Kotlin or from Objective-C to Swift in an afternoon. But how do we verify that the new code behaves exactly like the old code, including behavior that nobody documented?&lt;/p&gt;

&lt;p&gt;Anthropic's article is about migrating a Python service to Rust. It doesn't discuss Android or iOS.&lt;/p&gt;

&lt;p&gt;I want to look at how we can apply the same verification method to mobile and backend migrations. The technical claims about Kotlin, Swift, Envoy and app rollouts come from their respective documentation. The engineering recommendations are my judgment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why green tests aren't enough
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ei7r4n82jvafvjbhtfk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7ei7r4n82jvafvjbhtfk.png" alt="Headline &amp;quot;Why green tests aren't enough&amp;quot; with enough highlighted in a green pill. Body text: &amp;quot;Tests can pass and still miss behavior changes, hidden edge cases, and input differences.&amp;quot; Three icon cards read Changed Tests, Limited Coverage, and Input Differences. A laptop shows a Tests Passed checklist, and a magnifying glass over it reads Hidden Differences with a warning icon." width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Anthropic started with about 700 integration tests. They found two problems with using those tests to verify the migration.&lt;/p&gt;

&lt;p&gt;The first problem was that the tests depended on the existing Python implementation. They ran the Python API inside the test process and mocked other services in Python memory.&lt;/p&gt;

&lt;p&gt;This meant the tests also needed to change during the migration, and Claude helped change both the implementation and the tests.&lt;/p&gt;

&lt;p&gt;As Anthropic explains, "a 'pass' could mean that the code was right, or that the test had been changed in a way that let wrong code through."&lt;/p&gt;

&lt;p&gt;When they reviewed the migrated tests, they found "more than 100 weakened assertions."&lt;/p&gt;

&lt;p&gt;The second problem was test coverage. With just 20 binary options, you already have over a million possible combinations.&lt;/p&gt;

&lt;p&gt;Anthropic shared these numbers:&lt;/p&gt;

&lt;p&gt;"Our Rust API passed about 98% of its tests in April, yet only about a quarter of inputs matched on production traffic."&lt;/p&gt;

&lt;p&gt;One reason for the difference was how Python and Rust handled JSON tool calls. Python escaped certain characters, such as an emoji, into text codes. Rust kept the original characters.&lt;/p&gt;

&lt;p&gt;This meant the two prompts differed by a few bytes.&lt;/p&gt;

&lt;p&gt;We have similar problems when migrating mobile applications.&lt;/p&gt;

&lt;p&gt;Android's &lt;a href="https://developer.android.com/kotlin/add-kotlin" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; says Android Studio's converter "produces functionally-equivalent Kotlin code that compiles and runs," but also says "it's likely that you need to make additional optimizations to the converted code."&lt;/p&gt;

&lt;p&gt;Nullability is a good example. According to the documentation, Android Studio "defaults to the non-null assertion."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://kotlinlang.org/docs/java-interop.html" rel="noopener noreferrer"&gt;Kotlin's own docs&lt;/a&gt; explain what happens when you assign a value from Java to a non-nullable Kotlin type and "the value is actually null at runtime, Kotlin throws a NullPointerException."&lt;/p&gt;

&lt;p&gt;The original Java code might have been passing a null value around without crashing. After converting it to Kotlin, the same value can cause a crash.&lt;/p&gt;

&lt;p&gt;If your tests never pass that null value, all your tests can still pass.&lt;/p&gt;

&lt;p&gt;Kotlin's &lt;a href="https://kotlinlang.org/docs/mixing-java-kotlin-intellij.html" rel="noopener noreferrer"&gt;converter docs&lt;/a&gt; also mention that the converter "is not fool-proof."&lt;/p&gt;

&lt;p&gt;There's a similar concern when migrating Objective-C to Swift. Apple's &lt;a href="https://developer.apple.com/documentation/swift/migrating-your-objective-c-code-to-swift" rel="noopener noreferrer"&gt;migration guide&lt;/a&gt; says that if your Objective-C code doesn't have nullability annotations, "now's the time to add them."&lt;/p&gt;

&lt;p&gt;The reason is that &lt;a href="https://developer.apple.com/documentation/swift/objective-c-and-c-code-customization" rel="noopener noreferrer"&gt;those annotations control&lt;/a&gt; how declarations are imported into Swift.&lt;/p&gt;

&lt;p&gt;Android's &lt;a href="https://developer.android.com/kotlin/interop" rel="noopener noreferrer"&gt;Kotlin interop guide&lt;/a&gt; recommends the same for public Java APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the old code alive as the oracle
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8vtmwfb4h2aaesvhhkyj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8vtmwfb4h2aaesvhhkyj.png" alt="Headline &amp;quot;Keep the old code alive as the oracle&amp;quot; with oracle highlighted in a green pill. A cyan document labeled Legacy behavior connects to a center card that says Compare both, with a check mark, and then to a green document labeled Candidate behavior. A bottom banner with a wrench reads Apply fixes to both." width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Anthropic used the existing implementation as another way to verify the migration.&lt;/p&gt;

&lt;p&gt;In their words, "we used the existing system as an oracle to test parity during the migration."&lt;/p&gt;

&lt;p&gt;I think this is a useful approach for mobile migrations as well. Tests tell us what someone expected the code to do. The existing implementation gives us a reference for how the code actually behaves today, including its quirks.&lt;/p&gt;

&lt;p&gt;Apple recommends migrating per file, one class at a time. Its documentation also says "Don't delete the .m and .h files immediately; use them to troubleshoot."&lt;/p&gt;

&lt;p&gt;Android Studio also converts one file at a time.&lt;/p&gt;

&lt;p&gt;Migrating smaller parts of the application makes verification easier. If you find a difference in a single class, there are fewer places you need to investigate.&lt;/p&gt;

&lt;p&gt;There's another problem to consider. The existing implementation might still be changing while you're migrating it.&lt;/p&gt;

&lt;p&gt;Anthropic's Python API "continued changing throughout the migration, so parity was a moving target."&lt;/p&gt;

&lt;p&gt;They later introduced a merge check. Anyone changing the Python code had to make the corresponding change in Rust or request an exemption.&lt;/p&gt;

&lt;p&gt;I'd follow the same rule in an app. If someone fixes a bug in a Java class that already has a Kotlin implementation, apply the fix to both.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shadow the function inside the app
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F33vi4ks9mupdyo93skfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F33vi4ks9mupdyo93skfx.png" alt="Headline &amp;quot;Shadow the function inside the app&amp;quot; with Shadow highlighted in a green pill. Body text: &amp;quot;Run old and new code together, compare results, and return the legacy result.&amp;quot; Two glowing windows sit behind a magnifying glass with a check mark. A phone lists three steps: Old Code Use, New Code Try, and Return Legacy Result." width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Anthropic explains shadowing like this:&lt;/p&gt;

&lt;p&gt;"Running requests through old and new code and comparing the results is often called shadowing."&lt;/p&gt;

&lt;p&gt;In a mobile application, we can do this inside the app process without involving a server.&lt;/p&gt;

&lt;p&gt;GitHub's &lt;a href="https://github.com/github/scientist" rel="noopener noreferrer"&gt;Scientist README&lt;/a&gt; provides a useful example of this pattern.&lt;/p&gt;

&lt;p&gt;You put the existing implementation inside a &lt;code&gt;use&lt;/code&gt; block and the new implementation inside a &lt;code&gt;try&lt;/code&gt; block. The caller always receives the result from &lt;code&gt;use&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The experiment can also run the new block, randomize the execution order, compare the results, handle exceptions from the new implementation and publish the findings.&lt;/p&gt;

&lt;p&gt;Scientist is a Ruby library. We're only borrowing the pattern here.&lt;/p&gt;

&lt;p&gt;Below is a minimal Kotlin implementation. The candidate runs on an executor with a timeout. The &lt;code&gt;shadowRun&lt;/code&gt; function returns the legacy result right away, so a slow or hanging candidate doesn't block or delay the caller.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Callable&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ExecutorService&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Executors&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Future&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TimeUnit&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;atomic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AtomicInteger&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Step&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;Reporter&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;record&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;DiffRecord&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DiffRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;firstDiff&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;legacyLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;candidateLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;compareStep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;legacy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;DiffRecord&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;legacy&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;shared&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;minOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;legacy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="n"&gt;until&lt;/span&gt; &lt;span class="n"&gt;shared&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstOrNull&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;legacy&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="n"&gt;shared&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;DiffRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;legacy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;newShadowExecutor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ExecutorService&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;AtomicInteger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Executors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newCachedThreadPool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;concurrent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ThreadFactory&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;newThread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Runnable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Thread&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"shadow-${n.incrementAndGet()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;apply&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;isDaemon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;shadowRun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;legacy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Step&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Step&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;reporter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Reporter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;executor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ExecutorService&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;timeoutMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Long&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;legacy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Future&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;executor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;submit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Callable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;executor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Runnable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;candidateOut&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timeoutMs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TimeUnit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;MILLISECONDS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nf"&gt;compareStep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;candidateOut&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;reporter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cancel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;reporter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DiffRecord&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Exception&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// The caller already has the legacy result.&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The report can arrive after &lt;code&gt;shadowRun&lt;/code&gt; has returned. Remember to shut down the executor when the screen or process that created it ends.&lt;/p&gt;

&lt;p&gt;Notice that the record contains the position of the difference and the lengths of both results. It doesn't contain the actual text.&lt;/p&gt;

&lt;p&gt;Anthropic couldn't read customer requests or replies, so "instead of looking at text, we recorded the shape of each difference, such as where it happened in the service and how big it was."&lt;/p&gt;

&lt;p&gt;In a mobile app, those strings could contain a user's address, message or search query. We shouldn't send that information to analytics just to identify a difference.&lt;/p&gt;

&lt;p&gt;Another useful part of this approach is comparing the output at each step.&lt;/p&gt;

&lt;p&gt;Anthropic compared each stage before and after the model call, and "the first place they differed indicated roughly where the migration code differed from production code."&lt;/p&gt;

&lt;p&gt;If your implementation parses data, maps it and then formats it, call &lt;code&gt;shadowRun&lt;/code&gt; separately for each stage.&lt;/p&gt;

&lt;p&gt;Comparing only the final output tells you that something went wrong, but you still need to find out where.&lt;/p&gt;

&lt;p&gt;Be careful about which functions you shadow. Parsing, mapping, validation and price or date arithmetic are good candidates because they can be run twice safely.&lt;/p&gt;

&lt;p&gt;Don't do this with functions that write to a database or call a payment endpoint.&lt;/p&gt;

&lt;p&gt;Anthropic faced the same problem on the server. As they explain, "Common tools for shadowing often assume that a request can safely run twice, or that a service is deterministic," and their API needed to ensure that a request counted only once toward a customer's limits and bill.&lt;/p&gt;

&lt;p&gt;Scientist's README also warns that the two blocks run one after the other in random order. The data they depend on might change between executions, producing a mismatch even when there's no bug.&lt;/p&gt;

&lt;p&gt;Start by running an experiment where both blocks call the existing implementation. The mismatch rate from that experiment gives you your noise floor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mirror traffic when the backend is what's moving
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu9d6imamcmmn49o6q2nb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu9d6imamcmmn49o6q2nb.png" alt="Headline &amp;quot;Mirror traffic when the backend is what's moving&amp;quot; with Mirror highlighted in a green pill. Body text: &amp;quot;Send the same requests to both versions, compare responses, and keep users on the old one.&amp;quot; A phone sends the same requests through a Compare Responses scale card to two server racks labeled Old Backend and New Backend." width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're migrating a Java backend service to Kotlin, you can shadow entire requests instead of individual functions.&lt;/p&gt;

&lt;p&gt;Envoy's &lt;a href="https://www.envoyproxy.io/docs/envoy/v1.40.2/api-v3/config/route/v3/route_components.proto" rel="noopener noreferrer"&gt;route configuration&lt;/a&gt; provides a request mirror policy for this.&lt;/p&gt;

&lt;p&gt;The documentation describes a router that "is capable of shadowing traffic from one cluster to another," using a "fire and forget" approach.&lt;/p&gt;

&lt;p&gt;Envoy "will not wait for the shadow cluster to respond before returning the response from the primary cluster."&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;route&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;cluster&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api_legacy&lt;/span&gt;
  &lt;span class="na"&gt;request_mirror_policies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;cluster&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;api_candidate&lt;/span&gt;
      &lt;span class="na"&gt;runtime_fraction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;default_value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;numerator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
          &lt;span class="na"&gt;denominator&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;HUNDRED&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This configuration copies five percent of requests to the candidate service. Users continue receiving responses from the legacy service.&lt;/p&gt;

&lt;p&gt;Envoy also appends &lt;code&gt;-shadow&lt;/code&gt; to the incoming Host header. For example, it becomes &lt;code&gt;api.example.com-shadow&lt;/code&gt;, so the candidate service must accept that host.&lt;/p&gt;

&lt;p&gt;One thing to keep in mind is that Envoy's mirror documentation explains how to copy the requests. It doesn't explain how to compare the responses.&lt;/p&gt;

&lt;p&gt;You'll need to implement that part yourself. You can log both responses using the same correlation ID or store the candidate's output somewhere you can join it with the original output.&lt;/p&gt;

&lt;p&gt;Anthropic's recommendation was "Carefully design the verification signal."&lt;/p&gt;

&lt;p&gt;If you want to know which step produced a different result in production, you need to build that into your verification process.&lt;/p&gt;

&lt;p&gt;You also need to account for nondeterminism before enabling mirroring.&lt;/p&gt;

&lt;p&gt;Claude can return different answers for the same request. To handle this, Anthropic "ran the model once and replayed the model output to Rust."&lt;/p&gt;

&lt;p&gt;Both implementations received identical model output, and every stage had to match exactly.&lt;/p&gt;

&lt;p&gt;Your backend might not call an AI model, but it probably uses a clock, a random number generator or an ID generator.&lt;/p&gt;

&lt;p&gt;Pin or replay those values during verification. Otherwise, you might spend time investigating differences caused by the environment rather than the migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Group the diffs by fingerprint
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0beu03yh4gzssji85o3e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0beu03yh4gzssji85o3e.png" alt="Headline &amp;quot;Group the diffs by fingerprint&amp;quot; with fingerprint highlighted in a green pill. Body text: &amp;quot;Use a stable fingerprint to group similar differences and find the real issues faster.&amp;quot; A stack of documents flows into a Fingerprint icon, then splits into three grouped result cards. A large fingerprint icon sits on a pedestal at the right." width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you start shadowing production traffic, you'll have a lot of difference records to review.&lt;/p&gt;

&lt;p&gt;Anthropic recorded where the difference appeared in the code, which part of the prompt was affected, the byte where the difference started and the length of each result.&lt;/p&gt;

&lt;p&gt;They used this information as a fingerprint because "one bug tends to leave the same fingerprint on every request it affects."&lt;/p&gt;

&lt;p&gt;The problem is that a single bug "could produce hundreds of thousands of nearly identical diff records," which makes reviewing individual records impractical.&lt;/p&gt;

&lt;p&gt;Anthropic ran a script every 10 to 30 minutes. It grouped the records according to which fields differed and raised an alert only when it found a new kind of record.&lt;/p&gt;

&lt;p&gt;I'd use the same idea with the Kotlin example above.&lt;/p&gt;

&lt;p&gt;Group the records by step, the position of the first difference and the two lengths. A thousand mismatches can usually be reduced to a handful of causes.&lt;/p&gt;

&lt;p&gt;Start by fixing the largest group.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't let the checker be edited by the thing being checked
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F65skr9xv1g0ubteb02pp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F65skr9xv1g0ubteb02pp.png" alt="Headline &amp;quot;Don't let the checker be edited by the thing being checked&amp;quot; with checked highlighted in a green pill. Body text: &amp;quot;Keep your verification and test suite independent so the tests stay a fair judge.&amp;quot; A laptop shows a Test Suite with green check marks and a locked shield. A robot hand reaching for an edit card is blocked by a red X." width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Anthropic shared an example of an agent proposing a fix that passed verification but still wasn't suitable for production.&lt;/p&gt;

&lt;p&gt;The agent found that the Rust API was missing the description of a web search tool. It proposed copying the description into files that Rust could read.&lt;/p&gt;

&lt;p&gt;The prompts matched after the change, and the local verification passed.&lt;/p&gt;

&lt;p&gt;An engineer rejected the fix because the Rust implementation would need to call the actual service before launch anyway.&lt;/p&gt;

&lt;p&gt;Anthropic explains the limitation well:&lt;/p&gt;

&lt;p&gt;"A verifier can tell an agent whether the outputs matched, but not whether the fix is good enough to ship."&lt;/p&gt;

&lt;p&gt;I think this example, along with the more than 100 weakened assertions, gives us a useful rule for AI-assisted migrations.&lt;/p&gt;

&lt;p&gt;The comparator, recorded inputs and existing tests are what we use to judge whether the migration is correct.&lt;/p&gt;

&lt;p&gt;The person or agent doing the migration shouldn't change those checks in the same pull request without a human reviewing that part first.&lt;/p&gt;

&lt;p&gt;It's the cheapest control available. A pull request that changes both the implementation and its tests deserves closer review than one that only changes the implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Roll out in steps, and shadow before the store
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffq125spvm69vi5gmv5fs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffq125spvm69vi5gmv5fs.png" alt="Headline &amp;quot;Roll out in steps, and shadow before the store&amp;quot; with store highlighted in a green pill. Body text: &amp;quot;Verify with shadow runs, then enable for a small percentage, and roll out to everyone.&amp;quot; Three connected stages labeled Shadow Run, Small Percentage, and Everyone lead to a phone with an App Store download icon." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Anthropic describes the migration as building a second ship alongside the first while it continues sailing.&lt;/p&gt;

&lt;p&gt;Once they were confident that both implementations behaved the same way, "we moved the passengers over a few at a time."&lt;/p&gt;

&lt;p&gt;We can do something similar with mobile app releases, but there are limitations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://support.google.com/googleplay/android-developer/answer/6346149" rel="noopener noreferrer"&gt;Google Play's staged rollouts&lt;/a&gt; distribute an update to a percentage of randomly selected users.&lt;/p&gt;

&lt;p&gt;That percentage "won't increase automatically," so someone needs to increase it manually.&lt;/p&gt;

&lt;p&gt;You can halt the rollout, but users who have already received the update "will remain on that version."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.apple.com/help/app-store-connect/update-your-app/release-a-version-update-in-phases/" rel="noopener noreferrer"&gt;App Store Connect's phased release&lt;/a&gt; distributes an update over 7 days to users who have automatic updates enabled.&lt;/p&gt;

&lt;p&gt;You can pause the phased release for up to 30 days in total. However, anyone can still download the update manually at any time.&lt;/p&gt;

&lt;p&gt;The important thing to understand is that stopping a rollout prevents further distribution. It doesn't remove the version from devices that already have it.&lt;/p&gt;

&lt;p&gt;For a mobile app, I'd include shadowing in a release before switching to the new implementation.&lt;/p&gt;

&lt;p&gt;Release N contains both implementations. It returns the legacy result and reports fingerprints whenever the results differ.&lt;/p&gt;

&lt;p&gt;Release N+1 switches to the new implementation using a staged rollout. Do this only after the fingerprint counts for each step have stayed at zero for a period you decided on in advance.&lt;/p&gt;

&lt;p&gt;A backend service can often be rolled back quickly. We don't have that same option with an application binary that's already installed on a phone.&lt;/p&gt;

&lt;p&gt;So more of the verification needs to happen before we switch the implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this lands
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5wg5la9l28gmvk1z2yit.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5wg5la9l28gmvk1z2yit.png" alt="Headline &amp;quot;Where this lands&amp;quot; with lands highlighted in a green pill. Body text: &amp;quot;A safer way to replace old code with confidence by comparing results, reducing risk, and keeping users stable.&amp;quot; Three icon cards read Replace Old Code, Reduce Risk, and Keep Users Stable. A phone on the right shows a large green check mark." width="799" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Anthropic describes how the engineering work shifted toward writing "the rules and checks that agents worked within."&lt;/p&gt;

&lt;p&gt;I agree with that approach.&lt;/p&gt;

&lt;p&gt;If an AI agent can generate the implementation in a week, spending only an afternoon planning how to verify it isn't enough.&lt;/p&gt;

&lt;p&gt;Decide how much time and effort you can spend on verification before starting the conversion. Use that budget to decide how much code you can safely migrate at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Anthropic, Migrating our Messages API to Rust (25 Nov 2026): &lt;a href="https://www.anthropic.com/research/migrating-api-to-rust" rel="noopener noreferrer"&gt;https://www.anthropic.com/research/migrating-api-to-rust&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Android Developers, Add Kotlin to an existing app: &lt;a href="https://developer.android.com/kotlin/add-kotlin" rel="noopener noreferrer"&gt;https://developer.android.com/kotlin/add-kotlin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Android Developers, Kotlin-Java interop: &lt;a href="https://developer.android.com/kotlin/interop" rel="noopener noreferrer"&gt;https://developer.android.com/kotlin/interop&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Kotlin, Calling Java from Kotlin: &lt;a href="https://kotlinlang.org/docs/java-interop.html" rel="noopener noreferrer"&gt;https://kotlinlang.org/docs/java-interop.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Kotlin, Mixing Java and Kotlin in one project: &lt;a href="https://kotlinlang.org/docs/mixing-java-kotlin-intellij.html" rel="noopener noreferrer"&gt;https://kotlinlang.org/docs/mixing-java-kotlin-intellij.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple, Migrating Your Objective-C Code to Swift: &lt;a href="https://developer.apple.com/documentation/swift/migrating-your-objective-c-code-to-swift" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/swift/migrating-your-objective-c-code-to-swift&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple, Objective-C and C Code Customization: &lt;a href="https://developer.apple.com/documentation/swift/objective-c-and-c-code-customization" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/swift/objective-c-and-c-code-customization&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub Scientist README: &lt;a href="https://github.com/github/scientist" rel="noopener noreferrer"&gt;https://github.com/github/scientist&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Envoy v1.40.2, route configuration, RequestMirrorPolicy: &lt;a href="https://www.envoyproxy.io/docs/envoy/v1.40.2/api-v3/config/route/v3/route_components.proto" rel="noopener noreferrer"&gt;https://www.envoyproxy.io/docs/envoy/v1.40.2/api-v3/config/route/v3/route_components.proto&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Play Console Help, Release app updates with staged rollouts: &lt;a href="https://support.google.com/googleplay/android-developer/answer/6346149" rel="noopener noreferrer"&gt;https://support.google.com/googleplay/android-developer/answer/6346149&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;App Store Connect Help, Release a version update in phases: &lt;a href="https://developer.apple.com/help/app-store-connect/update-your-app/release-a-version-update-in-phases/" rel="noopener noreferrer"&gt;https://developer.apple.com/help/app-store-connect/update-your-app/release-a-version-update-in-phases/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>testing</category>
      <category>ai</category>
    </item>
    <item>
      <title>Gemini Nano or the Cloud? Eight Checks Before You Move a Feature On-Device</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Mon, 30 Nov 2026 20:22:36 +0000</pubDate>
      <link>https://dev.to/prikshit/gemini-nano-or-the-cloud-eight-checks-before-you-move-a-feature-on-device-419b</link>
      <guid>https://dev.to/prikshit/gemini-nano-or-the-cloud-eight-checks-before-you-move-a-feature-on-device-419b</guid>
      <description>&lt;p&gt;&lt;em&gt;A decision guide from Google's own docs, plus judgment where the docs leave a choice. Every API status was checked on 25 November 2026, and every number is quoted from a Google page. The Kotlin samples were compiled against the current SDKs and were not run on a phone.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Firebase's hybrid inference docs have a section called "Features not yet supported for on-device inference". Function calling is on it, next to multi-turn chat and any request over 4,000 tokens.&lt;/p&gt;

&lt;p&gt;That one list tells you more about where a Gemini Nano feature should run than most demos do, so the rest of this guide comes from the Android, ML Kit, Firebase and AI Edge docs. Every cited page was opened on 25 November 2026, and each API's status is reported as the page stated it that day. No figure in this guide is a device measurement. Each number comes from a Google page, linked at the end. Where the docs leave a choice, the call is marked as judgment.&lt;/p&gt;

&lt;h2&gt;
  
  
  The short answer
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92l4poao5yfrlq7ie0kz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F92l4poao5yfrlq7ie0kz.png" alt="Side by side comparison. On device: use Gemini Nano for short, single shot text jobs on private data or offline, such as summarizing, proofreading, rewriting, classifying and pulling fields. Cloud: use a cloud model for tools, long context, real multi turn conversation and reach across every device." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use Gemini Nano for short, single-shot text jobs that touch private data or have to work offline: summarize a message, proofread it, classify it, pull fields out of it. Use a cloud model when the job needs tools, long context, a real conversation, or reach across every device you support.&lt;/p&gt;

&lt;p&gt;For an agent loop, the status list below points to prototyping on-device and shipping in the cloud for now. That is a reading of the current API statuses, not a test result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Status first
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwoqv0qbh33fuokzdadvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwoqv0qbh33fuokzdadvy.png" alt="Table of ML Kit, Firebase and LiteRT-LM APIs with versions and status labels as of 25 November 2026, from beta and alpha to preview, experimental and stable. A side note says ML Kit GenAI pages carry no SLA or deprecation policy, and the Agent API needs AICore Developer Preview enrollment, so it is still a prototype path." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every ML Kit GenAI page cited here carries the same notice: not subject to any SLA or deprecation policy, and changes may break backward compatibility. This is how each API was labeled on 25 November 2026.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ML Kit Prompt API (&lt;code&gt;genai-prompt:1.0.0-beta5&lt;/code&gt;): beta. The official get-started page still shows &lt;code&gt;1.0.0-beta4&lt;/code&gt;. Summarization, proofreading, rewriting and image description: beta.&lt;/li&gt;
&lt;li&gt;Structured output: alpha. Thinking mode: beta, and only on Gemini Nano 4 and higher. Prefix caching: experimental.&lt;/li&gt;
&lt;li&gt;Speech recognition, speech translation and text to speech: alpha.&lt;/li&gt;
&lt;li&gt;Function calling in the Prompt API: preview. The page says the Google account on the device must be in the AICore Developer Preview program.&lt;/li&gt;
&lt;li&gt;ML Kit Agent API (&lt;code&gt;genai-agent&lt;/code&gt;, version 1.0.0-alpha1) and the Embeddings API: preview, with the same enrollment line.&lt;/li&gt;
&lt;li&gt;Firebase AI Logic hybrid inference: experimental. The on-device library, &lt;code&gt;firebase-ai-ondevice&lt;/code&gt;, is at 16.0.0-beta08.&lt;/li&gt;
&lt;li&gt;LiteRT-LM: its overview page marks the Kotlin API "Stable" and Swift "Early Preview", though the newest Maven release listed that day was 0.20.0. The MediaPipe LLM Inference API is in maintenance-only mode, and Google points to LiteRT-LM instead. The experimental Google AI Edge SDK for Gemini Nano is deprecated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The line that matters most for shipping is the enrollment one. As written, the Agent API needs the device's Google account in a developer preview program, so it is still a prototype for ordinary users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 1: Does your user's phone have it?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8bk6x6f3qimohuotsde.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj8bk6x6f3qimohuotsde.png" alt="Flow diagram. Availability depends on RAM, OS version and AICore update status. Generation.checkStatus() returns AVAILABLE, which routes on device, or DOWNLOADABLE, DOWNLOADING or UNAVAILABLE, which route to the cloud. A banner reads &amp;quot;Check status before showing UI&amp;quot;." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The ML Kit page lists supported devices in three groups, by Gemini Nano version (2, 3 and 4), and adds that availability depends on RAM, OS version and the AICore update status. Android's overview says on-device models typically need more premium devices. The Prompt API also isn't supported on a device with an unlocked bootloader.&lt;/p&gt;

&lt;p&gt;For scale, a July 2026 Android Developers Blog post says Gemini Nano runs on over 140 million devices. The docs don't break that number down by device.&lt;/p&gt;

&lt;p&gt;You don't have to guess at runtime. The Prompt API reports &lt;code&gt;AVAILABLE&lt;/code&gt;, &lt;code&gt;DOWNLOADABLE&lt;/code&gt;, &lt;code&gt;DOWNLOADING&lt;/code&gt; or &lt;code&gt;UNAVAILABLE&lt;/code&gt;, and the docs say to call it before showing any related UI, so users never see AICore setup errors. The three Kotlin blocks in this post were compiled against the current SDKs, but they weren't run on a phone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mlkit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;common&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FeatureStatus&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mlkit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;genai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prompt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Generation&lt;/span&gt;

&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="nf"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;ON_DEVICE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;CLOUD&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;routeForThisDevice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Generation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;checkStatus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;FeatureStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;AVAILABLE&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ON_DEVICE&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CLOUD&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the feature has to work for everyone, on-device can't be the only path.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 2: Latency
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgvmk0wyfvmcy53txlmd5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgvmk0wyfvmcy53txlmd5.png" alt="A cloud request makes a network round trip, while on device runs model initialization and then generation locally. Side notes say output length drives speed and inference runs only in the foreground. Measure time to first token and total inference time on the slowest phone you support." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On-device removes the network round trip. The Gemini Nano page adds that inference speed then depends on device hardware.&lt;/p&gt;

&lt;p&gt;In the AICore test app, the first inference after selecting a model can take up to a minute while the model initializes in memory, and both the ML Kit and Firebase SDKs offer a warm-up call that loads it early. Output length matters most. The prompt guide says inference speed depends heavily on how much the model writes, and an Android Developers Blog post about a sample app reports a prompt rewrite that took one response from 13 seconds to under 2. That figure comes from one demo app. On-device inference only runs while your app is in the foreground.&lt;/p&gt;

&lt;p&gt;The AICore app's Debug info screen shows time to first token, total inference time and token rates on your own hardware. Read it on the slowest phone you support before you call a feature instant. The docs give no cloud latency figure either, so that side of the comparison has to come from your own requests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 3: Privacy and offline use
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fort1tmlvknsjmjgmsc9d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fort1tmlvknsjmjgmsc9d.png" alt="Three panels. What on device gives you: no stored record, no direct internet access for AICore, prompts stay on the phone. ONLY_ON_DEVICE keeps requests local and throws if unavailable; PREFER_ON_DEVICE can fall back to the cloud. Caveats: your tools can call the network, offline needs a downloaded model, and monitoring shows no on device data." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Gemini Nano page says AICore doesn't store a record of the input or the output after processing, and that AICore has no direct internet access. Model downloads go through the open-source Private Compute Services companion APK. Prompts stay on the device, and the feature keeps working without a reliable connection.&lt;/p&gt;

&lt;p&gt;Two details can quietly break a "never leaves the phone" promise. In Firebase's &lt;code&gt;PREFER_ON_DEVICE&lt;/code&gt; mode, a request falls back to the cloud model when the on-device model is unavailable or doesn't support the request. If your privacy promise is absolute, use &lt;code&gt;ONLY_ON_DEVICE&lt;/code&gt; and handle the exception. And in the Agent API, tools you write can still call the network, which Google's page says outright.&lt;/p&gt;

&lt;p&gt;Offline also assumes the model is already on the phone. The Firebase SDK does not trigger the download for you when the model is missing. One cost of this privacy is that the Firebase console's AI monitoring shows no data for on-device inference, including logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 4: Cost
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm34754ht1cr46ujel4um.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm34754ht1cr46ujel4um.png" alt="A balance scale between an on device Gemini Nano chip and a cloud model with coins. On device has no per request model cost; cloud pricing depends on the model you choose." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Google's pages are consistent here. ML Kit's GenAI page lists "no additional server cost incurred for each API call", and Firebase lists inference at no cost. The Android hybrid page adds that moving routine tasks to the device lowers cloud inference cost.&lt;/p&gt;

&lt;p&gt;The cloud side has a free way in. Firebase AI Logic itself is free. Gemini Developer API charges depend on the model, a free tier exists without a billing account, and some models, especially preview ones, can require billing. For the cloud calls you do make, Firebase supports spend caps and App Check to limit abuse and surprise charges.&lt;/p&gt;

&lt;p&gt;What on-device doesn't remove is the evaluation work. Google's guide for direct model access recommends an evaluation set, a run per Gemini Nano version, and at least 3 to 5 prompt iterations. Budget that time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 5: Context length and output length
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F66eflu93g516isi8hw3o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F66eflu93g516isi8hw3o.png" alt="Input and output documents with length brackets. Gemini Nano on device is best for short inputs, single turn jobs and short output. A cloud model handles long context, multi turn conversations and larger outputs." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the check with the hardest numbers. The Prompt API's get-started page says input must fit in the context window, under 4,000 tokens or about 3,000 English words, and that use cases needing more than 4K tokens of output should be avoided. Firebase's hybrid page repeats the 4,000 token cap and recommends avoiding on-device use cases that need more than 256 tokens of output.&lt;/p&gt;

&lt;p&gt;What happens at the limit depends on the mode. &lt;code&gt;PREFER_ON_DEVICE&lt;/code&gt; falls back to the cloud for a request over 4,000 tokens. &lt;code&gt;ONLY_ON_DEVICE&lt;/code&gt; throws.&lt;/p&gt;

&lt;p&gt;The Agent API pages give no token number. They say on-device models have smaller context windows than server models, and that every tool you register uses up part of that window. For comparison, the Gemini API models page lists a 1M token context for the Gemini 4 models, including Gemini 4 Hydrogen, as of 25 November 2026.&lt;/p&gt;

&lt;p&gt;The feature surface also changes with the SDK. ML Kit's direct access accepts up to 10 images in one request. Firebase's on-device path accepts text, or text with a single Bitmap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 6: Model size and quality limits
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn4145a7udl1fvfxru21q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fn4145a7udl1fvfxru21q.png" alt="A phone showing Gemini Nano between two panels. On device: a smaller model, efficient for focused tasks, with quality trade offs. Cloud: larger models with higher quality for complex tasks. Takeaway: use the cloud when quality is critical." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Google's own framing is modest. The overview lists the on-device jobs as short content: summarize, proofread or rewrite a short chat message or email, describe images, handle sensitive data, transcribe a short audio clip. Chatbots, image generation, real-time translation and multi-agent work are listed under cloud.&lt;/p&gt;

&lt;p&gt;The task APIs are narrower on purpose. They use fixed fine-tuned adapters, and the docs spell out the limits: image descriptions are generic and short, summaries are 1 to 3 bullet points, rewriting offers predefined styles. Direct model access gives you freedom and costs more effort, and the docs call that effort high because of prompt engineering and quality assurance.&lt;/p&gt;

&lt;p&gt;A few more limits are worth knowing. Different Gemini Nano versions can return different output for the same prompt, so you evaluate per version. Firebase says only English and Korean have been validated for on-device inference, while an April 2026 Android Developers Blog post says Gemma 4, the base for Gemini Nano 4, supports over 140 languages. The pages cited here don't reconcile those two, and honestly that gap still needs an explanation from Google. Test any other language on a device before you promise it. Last, in Firebase's on-device path, multi-turn chat is flattened into a single text prompt, so the model doesn't see roles and is less precise than a cloud model. Firebase recommends &lt;code&gt;ONLY_IN_CLOUD&lt;/code&gt; for chat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Check 7: Tool calling and agent loops
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fznblj2ad2gm5nenfs9ek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fznblj2ad2gm5nenfs9ek.png" alt="A robot at a laptop inside a tool loop. ML Kit: function calling is in preview and needs AICore Developer Preview enrollment. Firebase: the hybrid model does not support on device tools." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where the docs say the most, and where you should be most careful. Firebase's hybrid path doesn't support tools on-device at all, and it doesn't fall back to the cloud for them automatically. Its recommendation is &lt;code&gt;ONLY_IN_CLOUD&lt;/code&gt; if you want tools.&lt;/p&gt;

&lt;p&gt;The ML Kit route does support them. Function calling in the Prompt API needs Gemini Nano 4, which today means the preview model and a device enrolled in the developer preview, except on the Galaxy Z Flip 8 and Fold 8, where the page says Nano 4 is already in production. The SDK doesn't validate or run what the model proposes. The Agent API adds a managed loop with a default of 10 turns, and its failure codes include &lt;code&gt;MAX_TURNS_EXCEEDED&lt;/code&gt;, &lt;code&gt;NOT_AVAILABLE&lt;/code&gt; and &lt;code&gt;BUSY&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What the docs say about reliability is blunt. Both the function calling and Agent API pages caution that the model may not suggest the correct tool or arguments. Because Gemini Nano generates tool names without strict schema constraints, it can emit near-miss names that match nothing you registered, and Google asks you to keep your KDoc wording consistent with method names and to handle unknown names gracefully. A large set of tools makes the model more error-prone and uses context. For deterministic tool choice the Agent API page suggests &lt;code&gt;temperature = 0.0f&lt;/code&gt; and warns against values above 0.4f. Thinking mode, on Nano 4 and higher, is documented as improving function-calling accuracy.&lt;/p&gt;

&lt;p&gt;None of these pages publishes a tool-call success rate, so your own evaluation set has to supply it.&lt;/p&gt;

&lt;p&gt;For contrast, LiteRT-LM lists function calling with constrained decoding for improved accuracy, but its Kotlin guide says tools only work with models that support them, such as FunctionGemma. Google's Android overview routes a single-agent loop to the ML Kit Agent API on-device, and routes the same job to a custom backend in the cloud. The status list is a reason to hold off on that on-device row for now.&lt;/p&gt;

&lt;p&gt;You can write this guard today, whichever SDK you pick. When the model names a tool that doesn't exist, answer with an error that lists the real tools instead of crashing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;typealias&lt;/span&gt; &lt;span class="nc"&gt;Tool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;

&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;runTool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Tool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Map&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;tool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"error"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s2"&gt;"Unknown tool '$name'. Available tools: ${tools.keys.joinToString()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"result"&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nf"&gt;tool&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Check 8: Battery, quotas and updates
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fopfv67kg488q1h33s096.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fopfv67kg488q1h33s096.png" alt="A phone with a battery icon between three panels: check battery impact and keep tasks light, check usage limits for on device features, and plan for regular model updates." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The docs give no battery figure for an app. What they give is a set of limits that exist partly to protect the battery. AICore enforces an inference quota per app. Too many requests in a short time return &lt;code&gt;BUSY&lt;/code&gt;, and &lt;code&gt;PER_APP_BATTERY_USE_QUOTA_EXCEEDED&lt;/code&gt; can be returned when an app passes a long-duration quota such as a daily one. Inference in the background, including from a foreground service, returns &lt;code&gt;BACKGROUND_USE_BLOCKED&lt;/code&gt;. The Agent API's turn limit is also described as a way to conserve battery.&lt;/p&gt;

&lt;p&gt;Google's posts do make relative claims. An April 2026 post on the Gemma 4 preview models says they are up to 4x faster than previous versions and use up to 60% less battery. A November 2026 post says Gemini Nano 4 gives up to a 3x speedup and cuts memory by up to 4x under internal benchmarks. The multipliers differ and neither names a device nor a prompt, so run your own measurements.&lt;/p&gt;

&lt;p&gt;Updates are the other half. AICore downloads and updates Gemini Nano, so it doesn't count against your APK, disk or memory budget, and it also means the model under your prompts can change without a release from you. &lt;code&gt;getBaseModelName()&lt;/code&gt; tells you which version is on a device. The release stage setting chooses stable or preview, and Firebase's examples put Nano 2 and 3 in the stable category and Nano 4 in preview. A freshly reset phone can also fail with AICore binding or feature-not-found errors until it finishes its first configuration download, which Google says usually takes a few minutes to a few hours. All of it points the same way. Keep a cloud path ready for &lt;code&gt;BUSY&lt;/code&gt;, quota errors and &lt;code&gt;UNAVAILABLE&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring the cloud fallback
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frx98izh563q27sn9qi7f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frx98izh563q27sn9qi7f.png" alt="The four Firebase inference modes around a phone: PREFER_ON_DEVICE, ONLY_ON_DEVICE, PREFER_IN_CLOUD and ONLY_IN_CLOUD. Takeaway: use ONLY_ON_DEVICE for strict privacy and the other modes when fallback is fine." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Firebase AI Logic's hybrid API gives you four modes. They are worth choosing per feature.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PREFER_ON_DEVICE&lt;/code&gt;: on-device when available and supported, otherwise the cloud model. This fits a feature that can run locally but must reach every device.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ONLY_ON_DEVICE&lt;/code&gt;: on-device or an exception. This fits a privacy promise.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;PREFER_IN_CLOUD&lt;/code&gt;: cloud when online, on-device only when the phone is offline.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ONLY_IN_CLOUD&lt;/code&gt;: cloud or an exception. Firebase suggests it for tools and chat.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You must name the cloud model yourself, because the SDK has no default. Each response also carries an &lt;code&gt;inferenceSource&lt;/code&gt; of &lt;code&gt;ON_DEVICE&lt;/code&gt; or &lt;code&gt;IN_CLOUD&lt;/code&gt;, so you can log which path served it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Firebase&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GenerativeModel&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;InferenceMode&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OnDeviceConfig&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GenerativeBackend&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PublicPreviewAPI&lt;/span&gt;

&lt;span class="nd"&gt;@OptIn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PublicPreviewAPI&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;hybridModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;neverLeaveDevice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;GenerativeModel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;neverLeaveDevice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;InferenceMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ONLY_ON_DEVICE&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;InferenceMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PREFER_ON_DEVICE&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ai&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;backend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;GenerativeBackend&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;googleAI&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;generativeModel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;modelName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"gemini-4-hydrogen"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;onDeviceConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OnDeviceConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If routing has to react to network latency, battery level, processor load or how hard the query is, Android's hybrid page describes custom routing and names Gboard and Kakao Mobility as apps that built their own.&lt;/p&gt;

&lt;h2&gt;
  
  
  When you ship the model yourself
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F059n6c1z7ym7tndrl9kc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F059n6c1z7ym7tndrl9kc.png" alt="LiteRT-LM versus AICore. With LiteRT-LM you bundle and manage the model yourself, with full control over version and updates. With AICore, Google provides and updates the model on demand, keeping your app smaller." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LiteRT-LM is the other on-device route, and it changes the trade. You choose the model and you carry it. Google's overview lists Gemma-4-E2B at 2.58 GB, and its table shows time to first token of 0.3 seconds on a Galaxy S26 Ultra GPU and 1.8 seconds on its CPU, with peak CPU memory of 676 MB on the GPU and 1,733 MB on the CPU. Those are Google's published figures for one phone.&lt;/p&gt;

&lt;p&gt;In return, Google's overview lists Android, iOS, web and desktop support, GPU and NPU acceleration, and models from Gemma to Llama, Phi-4 and Qwen. What the Gemini Nano page says AICore handles for you (the download, the updates, the disk and memory cost) becomes yours.&lt;/p&gt;

&lt;h2&gt;
  
  
  The decision checklist
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqd5s81cpjijhb7nbvnsi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqd5s81cpjijhb7nbvnsi.png" alt="A numbered checklist of eight checks: every user and device, input and output length, tools or multi turn chat, data never leaves the device, works offline, foreground only, evaluation on each Nano version, and API status risk. If a feature fails an important check, use hybrid or cloud." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Answer these in order. The first no that matters usually settles the route.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Must the feature work for every user on every device you support? If yes, use hybrid or cloud, never on-device alone.&lt;/li&gt;
&lt;li&gt;Does the input fit under about 3,000 English words, with output short enough to stay under 256 tokens? If no, use the cloud.&lt;/li&gt;
&lt;li&gt;Does it need tools or a real multi-turn chat? If yes, use the cloud unless you accept preview status and a developer preview enrollment.&lt;/li&gt;
&lt;li&gt;Do you tell users their data never leaves the device? If yes, use &lt;code&gt;ONLY_ON_DEVICE&lt;/code&gt; and decide what the screen does when it's unavailable.&lt;/li&gt;
&lt;li&gt;Must it work offline? If yes, check that the model is already downloaded before you promise it.&lt;/li&gt;
&lt;li&gt;Can it run only while the app is in the foreground? If no, use the cloud.&lt;/li&gt;
&lt;li&gt;Have you run an evaluation set on each Gemini Nano version you target, and read time to first token on your slowest device? If no, don't promise quality or speed yet.&lt;/li&gt;
&lt;li&gt;Can you live with the API changing under you, given the status list above? If no, wait, or use the cloud.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A feature that passes all eight can go on-device. Most features won't pass all eight today, and Google's own docs describe hybrid inference for exactly that case. It can run locally, but not every device can run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;p&gt;All pages opened on 25 November 2026. Page dates are the "last updated" lines the pages show, in UTC.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gemini Nano, Android Developers (updated 29 Oct 2026): &lt;a href="https://developer.android.com/ai/gemini-nano" rel="noopener noreferrer"&gt;https://developer.android.com/ai/gemini-nano&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Build agentic workflows with Gemini Nano (updated 18 Nov 2026): &lt;a href="https://developer.android.com/ai/gemini-nano/mlkit-agent-api" rel="noopener noreferrer"&gt;https://developer.android.com/ai/gemini-nano/mlkit-agent-api&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Choose an AI/ML solution, Android overview (updated 16 Nov 2026): &lt;a href="https://developer.android.com/ai/overview" rel="noopener noreferrer"&gt;https://developer.android.com/ai/overview&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Hybrid inference, Android (updated 8 Oct 2026): &lt;a href="https://developer.android.com/ai/hybrid" rel="noopener noreferrer"&gt;https://developer.android.com/ai/hybrid&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;ML Kit GenAI APIs overview and device support (updated 10 Nov 2026): &lt;a href="https://developers.google.com/ml-kit/genai" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;ML Kit Prompt API (updated 27 Oct 2026): &lt;a href="https://developers.google.com/ml-kit/genai/prompt/android" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/prompt/android&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Prompt API, get started (updated 27 Oct 2026): &lt;a href="https://developers.google.com/ml-kit/genai/prompt/android/get-started" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/prompt/android/get-started&lt;/a&gt; (this page still shows &lt;code&gt;1.0.0-beta4&lt;/code&gt;; the article pins &lt;code&gt;1.0.0-beta5&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Prompt API, function calling (updated 18 Nov 2026): &lt;a href="https://developers.google.com/ml-kit/genai/prompt/android/function-calling" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/prompt/android/function-calling&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Prompt API, thinking mode (updated 27 Oct 2026): &lt;a href="https://developers.google.com/ml-kit/genai/prompt/android/thinking-mode" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/prompt/android/thinking-mode&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Prompt API, select a model (updated 27 Oct 2026): &lt;a href="https://developers.google.com/ml-kit/genai/prompt/android/select-model" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/prompt/android/select-model&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Prompt API, evaluate prompt quality and prompt design: &lt;a href="https://developers.google.com/ml-kit/genai/prompt/android/evaluate-prompt" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/prompt/android/evaluate-prompt&lt;/a&gt; and &lt;a href="https://developers.google.com/ml-kit/genai/prompt/android/prompt-design" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/prompt/android/prompt-design&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;ML Kit agentic workflows (updated 16 Nov 2026) and define tools (updated 18 Nov 2026): &lt;a href="https://developers.google.com/ml-kit/genai/agent/android" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/agent/android&lt;/a&gt; and &lt;a href="https://developers.google.com/ml-kit/genai/agent/android/define-tools" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/agent/android/define-tools&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;AICore Developer Preview (updated 19 Nov 2026): &lt;a href="https://developers.google.com/ml-kit/genai/aicore-dev-preview" rel="noopener noreferrer"&gt;https://developers.google.com/ml-kit/genai/aicore-dev-preview&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Firebase AI Logic, hybrid on-device inference for Android (updated 18 Nov 2026): &lt;a href="https://firebase.google.com/docs/ai-logic/hybrid/android/get-started" rel="noopener noreferrer"&gt;https://firebase.google.com/docs/ai-logic/hybrid/android/get-started&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Firebase AI Logic, hybrid configuration options (updated 18 Nov 2026): &lt;a href="https://firebase.google.com/docs/ai-logic/hybrid/android/configuration-options" rel="noopener noreferrer"&gt;https://firebase.google.com/docs/ai-logic/hybrid/android/configuration-options&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Firebase AI Logic pricing (updated 18 Nov 2026): &lt;a href="https://firebase.google.com/docs/ai-logic/pricing" rel="noopener noreferrer"&gt;https://firebase.google.com/docs/ai-logic/pricing&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Gemini API models: &lt;a href="https://ai.google.dev/gemini-api/docs/models" rel="noopener noreferrer"&gt;https://ai.google.dev/gemini-api/docs/models&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;LiteRT-LM overview (updated 6 Oct 2026) and Kotlin guide: &lt;a href="https://ai.google.dev/edge/litert-lm/overview" rel="noopener noreferrer"&gt;https://ai.google.dev/edge/litert-lm/overview&lt;/a&gt; and &lt;a href="https://ai.google.dev/edge/litert-lm/android" rel="noopener noreferrer"&gt;https://ai.google.dev/edge/litert-lm/android&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;MediaPipe LLM Inference API: &lt;a href="https://ai.google.dev/edge/mediapipe/solutions/genai/llm_inference" rel="noopener noreferrer"&gt;https://ai.google.dev/edge/mediapipe/solutions/genai/llm_inference&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Google AI Edge SDK, experimental access (deprecated): &lt;a href="https://developer.android.com/ai/gemini-nano/experimental.md.txt" rel="noopener noreferrer"&gt;https://developer.android.com/ai/gemini-nano/experimental.md.txt&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Android Developers Blog, Build intelligent Android apps: On-device inference (21 Jul 2026): &lt;a href="https://developer.android.com/blog/posts/build-intelligent-android-apps-on-device-inference" rel="noopener noreferrer"&gt;https://developer.android.com/blog/posts/build-intelligent-android-apps-on-device-inference&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Android Developers Blog, What's new in intelligent apps at the Android Developer Summit (5 Nov 2026): &lt;a href="https://developer.android.com/blog/posts/android-intelligence-system-in-app-agents-ads" rel="noopener noreferrer"&gt;https://developer.android.com/blog/posts/android-intelligence-system-in-app-agents-ads&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Android Developers Blog, Announcing Gemma 4 in the AICore Developer Preview (2 Apr 2026): &lt;a href="https://android-developers.googleblog.com/2026/04/AI-Core-Developer-Preview.html" rel="noopener noreferrer"&gt;https://android-developers.googleblog.com/2026/04/AI-Core-Developer-Preview.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Google Maven, &lt;code&gt;genai-prompt&lt;/code&gt; (&lt;code&gt;1.0.0-beta5&lt;/code&gt; latest), &lt;code&gt;genai-agent&lt;/code&gt; and &lt;code&gt;litertlm-android&lt;/code&gt; version listings: &lt;a href="https://dl.google.com/android/maven2/com/google/mlkit/genai-prompt/maven-metadata.xml" rel="noopener noreferrer"&gt;https://dl.google.com/android/maven2/com/google/mlkit/genai-prompt/maven-metadata.xml&lt;/a&gt;, &lt;a href="https://dl.google.com/android/maven2/com/google/mlkit/genai-agent/maven-metadata.xml" rel="noopener noreferrer"&gt;https://dl.google.com/android/maven2/com/google/mlkit/genai-agent/maven-metadata.xml&lt;/a&gt; and &lt;a href="https://dl.google.com/android/maven2/com/google/ai/edge/litertlm/litertlm-android/maven-metadata.xml" rel="noopener noreferrer"&gt;https://dl.google.com/android/maven2/com/google/ai/edge/litertlm/litertlm-android/maven-metadata.xml&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>ai</category>
      <category>kotlin</category>
      <category>mobile</category>
    </item>
    <item>
      <title>AWS Device Farm Now Has Emulators. Your Flaky Tests Will Come With You.</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Thu, 26 Nov 2026 12:00:20 +0000</pubDate>
      <link>https://dev.to/prikshit/aws-device-farm-now-has-emulators-your-flaky-tests-will-come-with-you-5ec3</link>
      <guid>https://dev.to/prikshit/aws-device-farm-now-has-emulators-your-flaky-tests-will-come-with-you-5ec3</guid>
      <description>&lt;p&gt;&lt;em&gt;Which UI Tests Belong on Emulators and Simulators, and Which Stay on Real Devices&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo8ftnew7h6z7nhnilz3r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo8ftnew7h6z7nhnilz3r.png" alt="Title card: Your flaky tests will come with you" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;AWS Device Farm now runs Android emulators and iOS simulators next to real devices. The announcement is clear about where it expects you to use them: virtual devices for "stages that need high speed and volume, such as pull requests, code merges, and smoke tests", real devices for "later stages that need high fidelity", meaning regression and release testing.&lt;/p&gt;

&lt;p&gt;What the announcement can't do is make a test less flaky. A test that sleeps two seconds and hopes will sleep two seconds and hope on a virtual device.&lt;/p&gt;

&lt;p&gt;I read the announcement and the Device Farm developer guide.&lt;/p&gt;

&lt;p&gt;Startup time: the announcement says virtual devices on the latest OS "typically start in seconds" and others in around a minute. The developer guide is more precise. The latest OS is usually ready in under 30 seconds, other versions in about a minute.&lt;/p&gt;

&lt;p&gt;Price: the announcement says virtual devices use "the existing metered pricing". The pricing page lists $0.17 per device minute, with a one-time trial of 1,000 minutes, and an unmetered plan from $250 per slot per month. I found no separate virtual device rate there, so check the console. Android unmetered slots now cover emulators. iOS simulators are metered only, and the guide says an unmetered request for one is rejected with an error.&lt;/p&gt;

&lt;p&gt;Limits worth knowing: default metered concurrency is five devices, and simulator jobs count against it. A device pool or a run can't mix virtual and physical devices. An automated run stops at 150 minutes. Virtual devices don't support VPC endpoint connectivity, and you can't set Android system properties on emulators.&lt;/p&gt;

&lt;p&gt;Setup: Android emulators run only on the &lt;code&gt;amazon_linux_2023&lt;/code&gt; test host. iOS simulators need a simulator build (arm64, no code signing) and the &lt;code&gt;macos_tahoe&lt;/code&gt; test host.&lt;/p&gt;

&lt;p&gt;Test frameworks: Instrumentation and Appium on Android, XCTest, XCTest UI and Appium on iOS. Detox and Flutter's integration_test are not on that list.&lt;/p&gt;

&lt;p&gt;Supported OS versions: the &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/apps.html" rel="noopener noreferrer"&gt;developer guide&lt;/a&gt; says emulators run Android 15, 16 and 17, and since they're 64 bit x86_64 devices, any native libraries need an x86_64 build. iOS simulator versions are only listed in the console, which I couldn't open.&lt;/p&gt;

&lt;p&gt;The docs disagree with each other in two places. The announcement promises the same "private endpoint access" for virtual and real devices, while the guide says virtual devices don't support VPC endpoints. If your staging backend is private, believe the guide and test it early. And the Device Farm FAQ still says tests run on real devices, so that page is behind.&lt;/p&gt;

&lt;p&gt;Here's what I'd check first before a move: that console list, and whether your staging backend needs a VPC endpoint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmfhxysw3vvmcph4878hu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmfhxysw3vvmcph4878hu.png" alt="Common causes of flaky UI tests: fixed sleeps, animations, shared state and slow network, with the fix for each" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Apple's session on test repetitions lists the causes of unreliable tests as "race conditions, environment assumptions, global state, or communication with external services". None of the docs I read publish a share of failures per cause, so any claim that most flakes come from test design is my judgment, and I measured nothing.&lt;/p&gt;

&lt;p&gt;Waits come first. Espresso's guide names three workarounds that it calls bad: &lt;code&gt;Thread.sleep()&lt;/code&gt;, retry wrappers and &lt;code&gt;CountDownLatch&lt;/code&gt;. Of the first it says your tests "might still fail sometimes when executed on slower devices". A fixed delay tuned on your laptop is a guess about somebody else's CPU, and a cloud pool changes that CPU without telling the test.&lt;/p&gt;

&lt;p&gt;Animations are the second source. The Espresso setup page says "To avoid flakiness, we highly recommend that you turn off system animations on the virtual or physical devices used for testing", and lists the three system animation scales. The Android Gradle plugin can turn animations off for command line instrumented runs through &lt;code&gt;testOptions.animationsDisabled&lt;/code&gt;. AGP 9.5.3 does not do that by adding &lt;code&gt;--no-window-animation&lt;/code&gt; to the &lt;code&gt;am instrument&lt;/code&gt; command. Device Farm's Instrumentation page says it turns the three scales off itself when you use &lt;code&gt;AndroidJUnitRunner&lt;/code&gt;. That page doesn't mention emulators, so confirm it on a virtual device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fshjoc267bpi7a7zyq59h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fshjoc267bpi7a7zyq59h.png" alt="Test isolation on Android and Apple platforms: clean state between tests and randomized test order" width="800" height="410"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shared state and test order cause the failures that pass alone and break in the suite. Android Test Orchestrator runs each test in its own &lt;code&gt;Instrumentation&lt;/code&gt; instance, and its &lt;code&gt;clearPackageData&lt;/code&gt; flag clears the app's data between tests. On Apple's side, a test plan's Execution Order setting can pick a random order each time, which Apple says can uncover tests that depend on actions taken in other tests.&lt;/p&gt;

&lt;p&gt;The network is the last one. Android's testing strategy page lists mocked network access for feature tests, and brings in staging or production servers at the application and release candidate levels. For a pull request check, that means a fake server or fakes in the app instead of a live backend. Detox waits for in-flight requests, but it can't make a slow server fast.&lt;/p&gt;

&lt;p&gt;Espresso synchronizes only what posts to the main thread's message queue. The idling resource guide says so directly: "Espresso isn't aware of any other asynchronous operations, including those running on a background thread." Anything on a background thread that changes the UI needs an idling resource. The guide says &lt;code&gt;CountingIdlingResource&lt;/code&gt; is enough in most cases, recommends keeping the idling logic in the app and only registering it from tests, and asks you to unregister when you're done.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// App side: wrap the background work&lt;/span&gt;
&lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;LoadingIdler&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CountingIdlingResource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"repository-load"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;suspend&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;loadItems&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Item&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;LoadingIdler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchItems&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;LoadingIdler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decrement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Test side: register before the test needs it&lt;/span&gt;
&lt;span class="nd"&gt;@Before&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;registerIdler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;IdlingRegistry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LoadingIdler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@After&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;unregisterIdler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;IdlingRegistry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unregister&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LoadingIdler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The app module needs &lt;code&gt;implementation("androidx.test.espresso:espresso-idling-resource:3.7.0")&lt;/code&gt; for &lt;code&gt;CountingIdlingResource&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Compose tests are "synchronized by default with your UI", on a virtual clock, so they usually don't need this. The edge cases are work outside Compose and animations. For work outside Compose, the docs say to use &lt;code&gt;waitUntil&lt;/code&gt;, and they warn that a &lt;code&gt;CountDownLatch&lt;/code&gt; can behave unexpectedly because the test clock doesn't advance. For animations, turn &lt;code&gt;autoAdvance&lt;/code&gt; off and step the clock yourself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ui&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ui&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;junit4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;v2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;createAndroidComposeRule&lt;/span&gt;

&lt;span class="nd"&gt;@get&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nc"&gt;Rule&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;composeTestRule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;createAndroidComposeRule&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;MainActivity&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;itemsAppearAfterLoad&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;composeTestRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onNodeWithText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Load"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;performClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;composeTestRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;waitUntilAtLeastOneExists&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;hasTestTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"item-0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5_000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;composeTestRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onNodeWithTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"item-0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertIsDisplayed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@Test&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;detailsExpandAfterAnimation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;composeTestRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mainClock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;autoAdvance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="n"&gt;composeTestRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onNodeWithText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Expand"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;performClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;composeTestRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mainClock&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;advanceTimeBy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;composeTestRule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onNodeWithTag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"details"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assertIsDisplayed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second test controls time, so a fast emulator and a slow one behave the same. The first returns as soon as the node exists, with a five-second ceiling.&lt;/p&gt;

&lt;p&gt;Then switch on the isolation and animation settings once, in Gradle, so every virtual device behaves the same way.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// module build.gradle.kts&lt;/span&gt;
&lt;span class="n"&gt;android&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;defaultConfig&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;testInstrumentationRunner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"androidx.test.runner.AndroidJUnitRunner"&lt;/span&gt;
        &lt;span class="n"&gt;testInstrumentationRunnerArguments&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"clearPackageData"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;testOptions&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;animationsDisabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="n"&gt;execution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ANDROIDX_TEST_ORCHESTRATOR"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;androidTestImplementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.test:runner:1.7.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;androidTestUtil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.test:orchestrator:1.6.1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The orchestrator docs note one cost: each test restarts the app, so total time can go up. On a suite with shared-state flakes, I'd take that trade.&lt;/p&gt;

&lt;p&gt;Here's what I'd check on a flake first: a &lt;code&gt;Thread.sleep()&lt;/code&gt; left in the test, or a background load with no idling resource. Shared app state that leaks from the previous test is the other common one, and the orchestrator is the usual fix for that.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;waitForExistence(timeout:)&lt;/code&gt; waits for an element and returns &lt;code&gt;false&lt;/code&gt; if the timeout expires, so the assertion is on you. For something that should disappear, use an &lt;code&gt;XCTNSPredicateExpectation&lt;/code&gt; with a predicate such as &lt;code&gt;exists == false&lt;/code&gt;, then &lt;code&gt;wait(for:timeout:)&lt;/code&gt;. &lt;code&gt;XCTestCase&lt;/code&gt; reports a timeout as a failure on its own, which keeps the test from hanging quietly. Apple's docs: &lt;a href="https://developer.apple.com/documentation/xcuiautomation/xcuielement/waitforexistence(timeout:)" rel="noopener noreferrer"&gt;waitForExistence(timeout:)&lt;/a&gt;, &lt;a href="https://developer.apple.com/documentation/xctest/xctnspredicateexpectation" rel="noopener noreferrer"&gt;XCTNSPredicateExpectation&lt;/a&gt; and &lt;a href="https://developer.apple.com/documentation/xctest/xctestcase/wait(for:timeout:)" rel="noopener noreferrer"&gt;wait(for:timeout:)&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can pass a launch argument such as &lt;code&gt;-uitesting&lt;/code&gt; through &lt;a href="https://developer.apple.com/documentation/xcuiautomation/xcuiapplication/launcharguments" rel="noopener noreferrer"&gt;&lt;code&gt;XCUIApplication.launchArguments&lt;/code&gt;&lt;/a&gt;. What the app does with it, such as swapping in a fake backend, is your design.&lt;/p&gt;

&lt;p&gt;To find out whether a test is flaky, run it many times. Xcode 13 added test repetition with three modes: fixed iterations, until failure, and retry on failure. Apple's WWDC21 session, &lt;a href="https://developer.apple.com/videos/play/wwdc2021/10296/" rel="noopener noreferrer"&gt;Diagnose unreliable code with test repetitions&lt;/a&gt;, warns that "retrying failures can hide problems in the actual product", and says "it's best to use this mode temporarily to diagnose the failures". My position is that retry on failure in a pull request pipeline is a bandage that you should date and remove. On the command line, the same session says &lt;code&gt;xcodebuild&lt;/code&gt; flags override the test plan. Pass &lt;code&gt;-test-iterations&lt;/code&gt; with a number, and combine it with &lt;code&gt;-run-tests-until-failure&lt;/code&gt; to stop at the first failure.&lt;/p&gt;

&lt;p&gt;Use the repetition result as your evidence. A test that fails some of its 100 runs on a simulator on your Mac has a design problem you can fix. A test that passes all 100 there and fails in the cloud points at the environment, and you can only learn that once the first number is clean.&lt;/p&gt;

&lt;p&gt;Here's what I'd check on an XCUITest flake that is already failing some of those runs: a system alert the test doesn't handle, or an animation or a network call that the test never waits for.&lt;/p&gt;

&lt;p&gt;Flutter. The &lt;code&gt;integration_test&lt;/code&gt; package lets you use &lt;code&gt;flutter drive&lt;/code&gt; to run tests on a physical device or an emulator, and run them on Firebase Test Lab. Most of the waiting problems show up in &lt;code&gt;pumpAndSettle()&lt;/code&gt;. It pumps frames until none are scheduled, which the docs describe as essentially waiting for all animations to finish. If something animates forever, such as an indeterminate progress indicator, it throws after its timeout (ten minutes by default). The API docs call it "better practice to figure out exactly why each frame is needed, and then to pump exactly as many frames as necessary." Use &lt;code&gt;pumpAndSettle()&lt;/code&gt; for short, finite transitions, and pump a known duration when a spinner is on-screen.&lt;/p&gt;

&lt;p&gt;React Native. The React Native testing overview says end-to-end tests give the highest confidence, are "more prone to flakiness" than other types, and names Detox, Appium and Maestro as options. Detox is a gray-box tool, and its docs say it monitors network requests, the main thread, layout, timers, animations, the React Native JavaScript thread and the bridge, then "proceeds to the next action in the test code only after the app is stable". That removes many manual waits. The cost is strictness: by default Detox fails the test if timers or animations never finish, and the synchronization debugging logs show you which task kept the app busy. Fix the endless loader instead of turning synchronization off.&lt;/p&gt;

&lt;p&gt;Android's testing strategies page puts feature tests on local runs and emulators before merge, application tests on emulators and one phone and one foldable after merge, and release candidate tests on eight phones, a foldable and a tablet before release. The page says these guidelines "don't need to be followed strictly", and that tests can move for reasons such as "infrastructure cost, flakiness, and long test times". The Android Emulator page is even more direct: "In most cases, the emulator is the best option for your testing needs."&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo2o0v57ak8f3hc9n87jv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo2o0v57ak8f3hc9n87jv.png" alt="Virtual devices versus real devices, and which features to test on each" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So here is the split I'd start from.&lt;/p&gt;

&lt;p&gt;Run on emulators and simulators as pull request and merge checks: navigation and screen flows with a faked backend, form validation, state restoration after rotation and process death, accessibility labels, layout across screen sizes and API levels, deep links, notification payload handling. Android's CI page says a more advanced setup can test across environments such as API levels and screen sizes.&lt;/p&gt;

&lt;p&gt;Keep on real devices. Where I have a source, I quote it. The rest is my judgment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Camera. Apple says that when you run an app in a simulator, "some hardware-specific features might not be available", and to test the feature itself on a physical device. The Android Emulator's camera shows a simulated scene you can load pictures into, and Android's strategy page says camera apps "might depend on specific hardware features". Even Device Farm's real devices note that photos "might look dark and blurry" because of how they are mounted, so capture quality is a hands-on check.&lt;/li&gt;
&lt;li&gt;Biometrics. The emulator can simulate 10 different fingerprint scans, so I'd keep the prompt flow and error handling in the virtual run. In my judgment, the sensor itself, and anything specific to a vendor's face or fingerprint hardware, still belongs on a real device. The docs I read don't describe that difference.&lt;/li&gt;
&lt;li&gt;Push. The picture has changed. Xcode 14's release notes say Simulator supports remote notifications from iOS 16, through the APNs sandbox, on Apple Silicon or T2 Macs, and the Firebase docs support an emulator running Android 7.0 with Google APIs. That covers registration, payload handling and tap routing. In my judgment, I'd still send a production push to a real device before a release. I can't confirm that a virtual device exercises the production path, or each vendor's battery management.&lt;/li&gt;
&lt;li&gt;OEM quirks. Device Farm describes its real devices as "a variety of OEMs". Android's docs don't catalog vendor-specific behavior, so I can't cite one. It is the main reason a release candidate matrix of real phones exists.&lt;/li&gt;
&lt;li&gt;Performance. Android's Macrobenchmark guide says "We discourage running the benchmarks on an emulator, as they don't produce performance numbers representative of the end-user experience." Apple says simulators "don't replicate the performance or features of a physical device".&lt;/li&gt;
&lt;li&gt;Low-end hardware. An emulator or simulator runs on the host's CPU and memory, so its speed tells you about the host. In my judgment, if you care how the app behaves on a low-end phone, you still need a low-end phone.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's what I'd do when a failure shows up on only one model or one OEM skin: treat it as a real-device case and add that model to the release matrix, rather than chasing it on an emulator.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjluj3uzrmjq0z8zlv93d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fjluj3uzrmjq0z8zlv93d.png" alt="Cloud test matrix of frameworks and devices" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For the Android side, Gradle Managed Devices lets you declare emulators in the build. A device group runs the tests across all of its devices, and it's also how I'd build an API level matrix.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// module build.gradle.kts&lt;/span&gt;
&lt;span class="n"&gt;android&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;testOptions&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;managedDevices&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;localDevices&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pixel2api30"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;device&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Pixel 2"&lt;/span&gt;
                    &lt;span class="n"&gt;apiLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
                    &lt;span class="n"&gt;systemImageSource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"aosp"&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"pixel2api34"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;device&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Pixel 2"&lt;/span&gt;
                    &lt;span class="n"&gt;apiLevel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;
                    &lt;span class="n"&gt;systemImageSource&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"aosp"&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;groups&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ciPhones"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;targetDevices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allDevices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pixel2api30"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="n"&gt;targetDevices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;allDevices&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pixel2api34"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run one device with &lt;code&gt;./gradlew pixel2api30DebugAndroidTest&lt;/code&gt; or the whole group with &lt;code&gt;./gradlew ciPhonesGroupDebugAndroidTest&lt;/code&gt;. Use &lt;code&gt;allDevices&lt;/code&gt;, not &lt;code&gt;devices&lt;/code&gt;. The Android page still shows &lt;code&gt;devices["..."]&lt;/code&gt;, which does not compile on AGP 9. On servers without hardware rendering, such as GitHub Actions, pass &lt;code&gt;-Pandroid.testoptions.manageddevices.emulator.gpu=swiftshader_indirect&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Gradle Managed Devices gives you control of the image, and you provide the machines. Device Farm gives you managed capacity and one API for real and virtual devices, as long as your build fits the limits from section 1.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkmqn39ze7rnb0n390rg4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkmqn39ze7rnb0n390rg4.png" alt="AWS console view: pull request checks on virtual devices, release testing on real devices" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run this before you move a flaky test anywhere.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Run the test alone, 100 times, on one virtual device. On iOS use &lt;code&gt;-test-iterations&lt;/code&gt; with &lt;code&gt;-run-tests-until-failure&lt;/code&gt;. If it never fails, look at the suite or the environment.&lt;/li&gt;
&lt;li&gt;Read the failure. A timeout points at a wait. A "not found" right after a tap points at a missing synchronization.&lt;/li&gt;
&lt;li&gt;Search the test for &lt;code&gt;Thread.sleep&lt;/code&gt;, &lt;code&gt;sleep&lt;/code&gt;, &lt;code&gt;CountDownLatch&lt;/code&gt; and fixed &lt;code&gt;delay&lt;/code&gt; calls. Replace each with a condition: an idling resource, &lt;code&gt;waitUntil&lt;/code&gt;, &lt;code&gt;waitForExistence&lt;/code&gt; or an expectation.&lt;/li&gt;
&lt;li&gt;Run the whole suite in random order. On Android use the orchestrator with &lt;code&gt;clearPackageData&lt;/code&gt;. On iOS set Execution Order to random in the test plan.&lt;/li&gt;
&lt;li&gt;Turn off animations, then look for ones that never end. A spinner that runs forever will fail &lt;code&gt;pumpAndSettle()&lt;/code&gt; and Detox's idle check.&lt;/li&gt;
&lt;li&gt;Replace the live backend with a fake for pull request runs.&lt;/li&gt;
&lt;li&gt;If it fails only on one device model, one API level or one OEM, stop tuning it. That test belongs in your real device pool.&lt;/li&gt;
&lt;li&gt;Don't turn on retry as the fix. If you must use it, write down the date and remove it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Moving a clean, fast set of tests to virtual devices makes sense, and AWS now gives you a managed place to do it. Moving a flaky set there makes the failures more expensive to reproduce. Fix the waits first, repeat the test until you trust it, then decide which tests earn a place on real hardware.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;p&gt;All pages opened on 26 November 2026.&lt;/p&gt;

&lt;p&gt;AWS&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AWS Device Farm now supports Android emulators and iOS simulators (25 Nov 2026): &lt;a href="https://aws.amazon.com/about-aws/whats-new/2026/11/device-farm-virtual-devices/" rel="noopener noreferrer"&gt;https://aws.amazon.com/about-aws/whats-new/2026/11/device-farm-virtual-devices/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Testing on virtual devices in Device Farm: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/virtual-devices.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/virtual-devices.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Device support in AWS Device Farm: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/devices.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/devices.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Purchasing a device slot in Device Farm: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/how-to-purchase-device-slots.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/how-to-purchase-device-slots.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Limits in AWS Device Farm: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/limits.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/limits.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Test environment for Android devices: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environments-hosts-android.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environments-hosts-android.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Test environment for iOS devices: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environments-hosts-ios.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/custom-test-environments-hosts-ios.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Test frameworks and built-in tests: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apps in AWS Device Farm: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/apps.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/apps.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instrumentation tests in Device Farm: &lt;a href="https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-instrumentation.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-instrumentation.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;AWS Device Farm pricing: &lt;a href="https://aws.amazon.com/device-farm/pricing/" rel="noopener noreferrer"&gt;https://aws.amazon.com/device-farm/pricing/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;AWS Device Farm FAQs: &lt;a href="https://aws.amazon.com/device-farm/faqs/" rel="noopener noreferrer"&gt;https://aws.amazon.com/device-farm/faqs/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Android&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Espresso idling resources: &lt;a href="https://developer.android.com/training/testing/espresso/idling-resource" rel="noopener noreferrer"&gt;https://developer.android.com/training/testing/espresso/idling-resource&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Espresso setup instructions: &lt;a href="https://developer.android.com/training/testing/espresso/setup" rel="noopener noreferrer"&gt;https://developer.android.com/training/testing/espresso/setup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Synchronize your tests (Compose): &lt;a href="https://developer.android.com/develop/ui/compose/testing/synchronization" rel="noopener noreferrer"&gt;https://developer.android.com/develop/ui/compose/testing/synchronization&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Android Test Orchestrator (AndroidJUnitRunner): &lt;a href="https://developer.android.com/training/testing/instrumented-tests/androidx-test-libraries/runner" rel="noopener noreferrer"&gt;https://developer.android.com/training/testing/instrumented-tests/androidx-test-libraries/runner&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Scale your tests with build-managed devices: &lt;a href="https://developer.android.com/studio/test/managed-devices" rel="noopener noreferrer"&gt;https://developer.android.com/studio/test/managed-devices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;TestOptions, Android Gradle plugin API reference: &lt;a href="https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/dsl/TestOptions" rel="noopener noreferrer"&gt;https://developer.android.com/reference/tools/gradle-api/current/com/android/build/api/dsl/TestOptions&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Testing strategies: &lt;a href="https://developer.android.com/training/testing/fundamentals/strategies" rel="noopener noreferrer"&gt;https://developer.android.com/training/testing/fundamentals/strategies&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Continuous Integration basics: &lt;a href="https://developer.android.com/training/testing/continuous-integration" rel="noopener noreferrer"&gt;https://developer.android.com/training/testing/continuous-integration&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Run apps on the Android Emulator: &lt;a href="https://developer.android.com/studio/run/emulator" rel="noopener noreferrer"&gt;https://developer.android.com/studio/run/emulator&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Emulator extended controls: &lt;a href="https://developer.android.com/studio/run/emulator-extended-controls" rel="noopener noreferrer"&gt;https://developer.android.com/studio/run/emulator-extended-controls&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Macrobenchmark overview: &lt;a href="https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview" rel="noopener noreferrer"&gt;https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Firebase Cloud Messaging, Android client: &lt;a href="https://firebase.google.com/docs/cloud-messaging/android/get-started" rel="noopener noreferrer"&gt;https://firebase.google.com/docs/cloud-messaging/android/get-started&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Apple&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running your app on simulated or physical devices: &lt;a href="https://developer.apple.com/documentation/xcode/running-your-app-on-simulated-or-physical-devices" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcode/running-your-app-on-simulated-or-physical-devices&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Organizing tests into test plans: &lt;a href="https://developer.apple.com/documentation/xcode/organizing-tests-to-improve-feedback" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcode/organizing-tests-to-improve-feedback&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Diagnose unreliable code with test repetitions, WWDC21: &lt;a href="https://developer.apple.com/videos/play/wwdc2021/10296/" rel="noopener noreferrer"&gt;https://developer.apple.com/videos/play/wwdc2021/10296/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Xcode 14 release notes: &lt;a href="https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcode-release-notes/xcode-14-release-notes&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;waitForExistence(timeout:): &lt;a href="https://developer.apple.com/documentation/xcuiautomation/xcuielement/waitforexistence(timeout:)" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcuiautomation/xcuielement/waitforexistence(timeout:)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;wait(for:timeout:): &lt;a href="https://developer.apple.com/documentation/xctest/xctestcase/wait(for:timeout:)" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xctest/xctestcase/wait(for:timeout:)&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;XCTNSPredicateExpectation: &lt;a href="https://developer.apple.com/documentation/xctest/xctnspredicateexpectation" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xctest/xctnspredicateexpectation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;XCTWaiter: &lt;a href="https://developer.apple.com/documentation/xctest/xctwaiter" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xctest/xctwaiter&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;launchArguments: &lt;a href="https://developer.apple.com/documentation/xcuiautomation/xcuiapplication/launcharguments" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcuiautomation/xcuiapplication/launcharguments&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Flutter, React Native, Detox&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Flutter integration tests: &lt;a href="https://docs.flutter.dev/testing/integration-tests" rel="noopener noreferrer"&gt;https://docs.flutter.dev/testing/integration-tests&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;WidgetTester.pumpAndSettle: &lt;a href="https://api.flutter.dev/flutter/flutter_test/WidgetTester/pumpAndSettle.html" rel="noopener noreferrer"&gt;https://api.flutter.dev/flutter/flutter_test/WidgetTester/pumpAndSettle.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React Native testing overview: &lt;a href="https://reactnative.dev/docs/testing-overview" rel="noopener noreferrer"&gt;https://reactnative.dev/docs/testing-overview&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;How Detox works: &lt;a href="https://wix.github.io/Detox/docs/articles/how-detox-works" rel="noopener noreferrer"&gt;https://wix.github.io/Detox/docs/articles/how-detox-works&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Detox, dealing with synchronization issues: &lt;a href="https://wix.github.io/Detox/docs/troubleshooting/synchronization" rel="noopener noreferrer"&gt;https://wix.github.io/Detox/docs/troubleshooting/synchronization&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>ios</category>
      <category>testing</category>
      <category>mobile</category>
    </item>
    <item>
      <title>CocoaPods freezes on December 2. Here's the SwiftPM migration checklist I'd run first.</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Wed, 25 Nov 2026 08:20:27 +0000</pubDate>
      <link>https://dev.to/prikshit/cocoapods-freezes-on-december-2-heres-the-swiftpm-migration-checklist-id-run-first-2kfm</link>
      <guid>https://dev.to/prikshit/cocoapods-freezes-on-december-2-heres-the-swiftpm-migration-checklist-id-run-first-2kfm</guid>
      <description>&lt;p&gt;&lt;em&gt;Trunk goes read-only on 2 December 2026. Existing builds keep working, but the pods behind them stop getting updates. Here is how to list yours and plan the move to Swift Package Manager, for native iOS, Flutter and React Native.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Run this in the folder that holds your Podfile.lock. The shell blocks in this post are written for bash.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;awk &lt;span class="s1"&gt;'/^SPEC REPOS:/{s=1;next} /^[A-Z]/{s=0} s &amp;amp;&amp;amp; /^  [^ ]/{t=($0 ~ /^  trunk:/)} s &amp;amp;&amp;amp; t &amp;amp;&amp;amp; /^    - /{sub(/^    - /,"");print}'&lt;/span&gt; Podfile.lock
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every name it prints is a pod your app pulls from CocoaPods trunk. From Wednesday 2 December 2026, trunk stops accepting new pods and new versions. Your builds won't break that day, but those names are the dependencies that stop getting updates, so this CocoaPods to SwiftPM checklist starts with that list.&lt;/p&gt;

&lt;p&gt;It covers native iOS, Flutter and React Native, and it says where each one stands today. Every date and command traces to an official page listed at the end. This is a plan built from those pages, and I haven't run it on a real migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  What changes on 2 December, and what doesn't
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3zd70w9xnhwn0kswr4en.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3zd70w9xnhwn0kswr4en.png" alt="An iced-over CocoaPods Trunk server is marked Read-Only from 2 Dec 2026. A green path labelled Existing builds keep working leads to a phone and a tablet with check marks. A red path labelled New pods or new versions (updates) is blocked. An orange path is labelled Migrate to SwiftPM." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The CocoaPods team's &lt;a href="https://blog.cocoapods.org/CocoaPods-Specs-Repo/" rel="noopener noreferrer"&gt;read-only plan&lt;/a&gt; puts the permanent switch on 2 December 2026 and says any new podspec will be denied at the server level. It also planned a test run of the same behavior for 2 to 6 November.&lt;/p&gt;

&lt;p&gt;Still works after the switch:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Existing builds. The same post says the switch won't break builds for people using CocoaPods in 2026 onwards.&lt;/li&gt;
&lt;li&gt;Installing versions that are already published. Swift.org's &lt;a href="https://www.swift.org/blog/whats-new-in-swift-november-2026/" rel="noopener noreferrer"&gt;November edition&lt;/a&gt; says all current pods and versions stay available, in a read-only state.&lt;/li&gt;
&lt;li&gt;Your own spec repos and fully vendored dependencies. The CocoaPods post says they shouldn't be affected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stops working:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Publishing a new pod or a new version of one to trunk.&lt;/li&gt;
&lt;li&gt;Updates to every dependency you get through trunk. In Swift.org's words, pod authors can no longer publish updates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CocoaPods itself is in maintenance mode too. The team's &lt;a href="https://blog.cocoapods.org/CocoaPods-Support-Plans/" rel="noopener noreferrer"&gt;support plan&lt;/a&gt; aims for at least two releases a year to keep up with Xcode, and says there is no plan for new features.&lt;/p&gt;

&lt;p&gt;My read is that 2 December starts a clock. The first real problem is a pod that needs a fix for a new Xcode or a security issue and has no way to ship it. The CocoaPods post does say the dates aren't set in stone, but Swift.org and the Flutter docs both quote 2 December, so plan for that date.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Inventory your pods
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3mhploxuuxzvbfv3vsei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F3mhploxuuxzvbfv3vsei.png" alt="A Podfile.lock page lists four trunk pods, Alamofire, FirebaseCore, SDWebImage and Realm, plus external sources. A terminal running awk prints those names. Each name is checked for Package.swift: yes for Alamofire, FirebaseCore and Realm, and no for SDWebImage. A table records the same results and notes a SwiftPM alternative for SDWebImage." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The command at the top lists trunk pods. If it prints nothing, open Podfile.lock and look under SPEC REPOS. This command only reads the entry named &lt;code&gt;trunk&lt;/code&gt;. Pods installed with &lt;code&gt;:git&lt;/code&gt;, &lt;code&gt;:path&lt;/code&gt; or &lt;code&gt;:podspec&lt;/code&gt; show up under EXTERNAL SOURCES in the same file. They don't depend on trunk, but they do depend on CocoaPods, so write them down too.&lt;/p&gt;

&lt;p&gt;Next, find out which of those already work with SwiftPM. Swift.org's post says most maintained pods are already SwiftPM compatible, and that the easiest check is the Swift Package Index, since every package in it is a SwiftPM package. Search each name there. To script a first pass, this reads each pod's source repository from its podspec and asks GitHub whether a Package.swift sits in the repository root.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; pod &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$(&lt;/span&gt;awk &lt;span class="s1"&gt;'/^SPEC REPOS:/{s=1;next} /^[A-Z]/{s=0} s &amp;amp;&amp;amp; /^  [^ ]/{t=($0 ~ /^  trunk:/)} s &amp;amp;&amp;amp; t &amp;amp;&amp;amp; /^    - /{sub(/^    - /,"");print}'&lt;/span&gt; Podfile.lock&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;repo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;pod spec cat --regex &lt;span class="s2"&gt;"^${pod}\$"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; jq -r &lt;span class="s1"&gt;'.source.git // empty'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sed -E &lt;span class="s1"&gt;'s#\.git$##'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"$repo"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt;
    https://github.com/*&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="nv"&gt;raw&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$repo"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sed &lt;span class="s1"&gt;'s#https://github.com/#https://raw.githubusercontent.com/#'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="nv"&gt;code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}'&lt;/span&gt; &lt;span class="s2"&gt;"$raw/HEAD/Package.swift"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$pod  $repo  Package.swift: HTTP $code"&lt;/span&gt; &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    *&lt;span class="o"&gt;)&lt;/span&gt;
      &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$pod  ${repo:-no git source}  check by hand"&lt;/span&gt; &lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;esac&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A 200 means the default branch has a manifest, which tells you nothing about releases. Pods hosted outside GitHub, or with a name &lt;code&gt;pod spec cat&lt;/code&gt; can't match as a regex, are listed under 'check by hand'. SwiftPM's docs expect a &lt;code&gt;Package.swift&lt;/code&gt; in the root of the repository and a tag that is a full semantic version with major, minor and patch numbers, and they warn that a tag like &lt;code&gt;1.0&lt;/code&gt; isn't recognized, so tag releases as &lt;code&gt;1.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Put the result in a file in your repo with one row per pod and a yes or no for Package.swift. For the pods that say no, add a note on whether a SwiftPM alternative exists. The pods with neither are what the last section is for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Native iOS, in Xcode
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgren20pvf6jyq9a7fxs9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgren20pvf6jyq9a7fxs9.png" alt="Infographic titled Native iOS Migration, Move CocoaPods dependencies to SwiftPM in Xcode. Five steps sit beside an Xcode window where File, Add Package Dependency is chosen, then Alamofire is added from GitHub with the Up to Next Major Version rule. A Podfile loses its Alamofire and SnapKit lines, a Package.resolved file lists both versions, and a phone shows the built MyApp." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I haven't run the Xcode or iOS build steps in this post on a Mac. The menu names, flags and commands come from the official docs, starting with Apple's here, and Flutter's and React Native's later on.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Work on a branch. Keep the Podfile and Podfile.lock in version control, as the CocoaPods guide says, so you can go back.&lt;/li&gt;
&lt;li&gt;Take one pod from the inventory. In Xcode choose File &amp;gt; Add Package Dependency and paste the package's repository URL. Apple recommends the version requirement, which lets you accept updates up to the next major or minor version. Pick the products you need and add them to your targets. Apple also says to add package dependencies only from authors you trust, and that now applies to every URL you paste.&lt;/li&gt;
&lt;li&gt;Delete that pod's line from the Podfile, run &lt;code&gt;pod install&lt;/code&gt;, and build. Give each pod its own commit, so a bad move is easy to revert.&lt;/li&gt;
&lt;li&gt;Repeat until the Podfile has no pods left. Then run &lt;code&gt;pod deintegrate&lt;/code&gt;, which removes all traces of CocoaPods from your Xcode project, and delete the Podfile, the Podfile.lock and the &lt;code&gt;.xcworkspace&lt;/code&gt; that CocoaPods created, then open the &lt;code&gt;.xcodeproj&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Commit &lt;code&gt;Package.resolved&lt;/code&gt;. Xcode writes it with the exact Git commit each dependency resolves to, and Apple says to commit it so everyone, including CI, builds the same versions.&lt;/li&gt;
&lt;li&gt;On CI that calls &lt;code&gt;xcodebuild&lt;/code&gt; directly, also pass &lt;code&gt;-disableAutomaticPackageResolution&lt;/code&gt; so the build uses &lt;code&gt;Package.resolved&lt;/code&gt; as written. For private packages, Apple says to use SSH-based Git URLs and set up &lt;code&gt;known_hosts&lt;/code&gt; for the user that runs the job.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Flutter: SwiftPM is already the default
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fffigrg9v8zko4zso7hlw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fffigrg9v8zko4zso7hlw.png" alt="A phone with the Flutter logo sits between an iOS badge and a Mac. Three Package.swift boxes feed into the phone under Swift Package Manager. A CocoaPods fallback box shows a plugin with no Package.swift connecting on a dashed line." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flutter's docs say that as of the 3.44 release, Flutter uses Swift Package Manager for iOS and macOS native dependencies, that CocoaPods stays supported in maintenance mode, and that the CocoaPods registry becomes read-only on 2 December 2026.&lt;/p&gt;

&lt;p&gt;Upgrading and running your app adds the SwiftPM integration for you. Flutter falls back to CocoaPods for any dependency that doesn't support SwiftPM yet. To confirm the integration in Xcode, run the app and check that the Run Prepare Flutter Framework Script pre-action ran and that FlutterGeneratedPluginSwiftPackage is a target dependency.&lt;/p&gt;

&lt;p&gt;The Flutter tool decides per plugin by looking for a manifest at &lt;code&gt;ios/&amp;lt;plugin_name&amp;gt;/Package.swift&lt;/code&gt; (or the macOS or darwin equivalent), which is the layout the plugin docs describe. This lists which of your plugins have one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flutter pub get
&lt;span class="nb"&gt;cd&lt;/span&gt; .dart_tool
jq -r &lt;span class="s1"&gt;'.packages[] | "\(.name)\t\(.rootUri)"'&lt;/span&gt; package_config.json &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="nv"&gt;IFS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;$'\t'&lt;/span&gt; &lt;span class="nb"&gt;read&lt;/span&gt; -r name uri&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="s2"&gt;"${uri#file://}"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;pwd&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;continue&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; p &lt;span class="k"&gt;in&lt;/span&gt; ios macos darwin&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -f &lt;span class="s2"&gt;"$dir/$p/$name/Package.swift"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"SwiftPM     $name ($p)"&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; ls &lt;span class="s2"&gt;"$dir/$p"&lt;/span&gt;/*.podspec &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"CocoaPods   $name ($p)"&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
  &lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't remove CocoaPods until every plugin in your app reports SwiftPM. The docs say Flutter falls back to CocoaPods if any dependency lacks SwiftPM support, and that edits you made to the Podfile beyond Flutter plugins have to be removed by hand. When you're ready, the docs give these steps:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ios
pod deintegrate
&lt;span class="nb"&gt;cd&lt;/span&gt; ..
&lt;span class="c"&gt;# delete ios/Podfile, ios/Podfile.lock, ios/Pods/ and ios/.symlinks/ (if present)&lt;/span&gt;
&lt;span class="c"&gt;# remove any #include lines for Pods/Target Support Files from&lt;/span&gt;
&lt;span class="c"&gt;# ios/Flutter/Debug.xcconfig and ios/Flutter/Release.xcconfig&lt;/span&gt;
flutter clean
flutter pub get
flutter run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a plugin needs a higher iOS version than your app, Xcode reports a Target Integrity error. Raise your Minimum Deployments, then run &lt;code&gt;flutter build ios --config-only&lt;/code&gt; to regenerate the configuration.&lt;/p&gt;

&lt;p&gt;To turn SwiftPM off, which Flutter says not to do in general, use one of these two. The docs add that disabling it won't be allowed in the future, and that SwiftPM stays integrated in your project when you do.&lt;/p&gt;

&lt;p&gt;For every project, as the current user:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;flutter config --no-enable-swift-package-manager
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For one project only, in &lt;code&gt;pubspec.yaml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# pubspec.yaml, for one project
&lt;/span&gt;&lt;span class="na"&gt;flutter&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;config&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;enable-swift-package-manager&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To undo the first one, run &lt;code&gt;flutter config --enable-swift-package-manager&lt;/code&gt;. Flutter prints a warning each time it runs with SwiftPM off: "Enabling Swift Package Manager will be required in a future version of Flutter." &lt;/p&gt;

&lt;p&gt;If you maintain a plugin, the &lt;a href="https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors" rel="noopener noreferrer"&gt;plugin author guide&lt;/a&gt; has the full steps. In short, add &lt;code&gt;ios/&amp;lt;plugin_name&amp;gt;/Package.swift&lt;/code&gt; with a dependency on FlutterFramework, move your sources under &lt;code&gt;Sources/&amp;lt;plugin_name&amp;gt;&lt;/code&gt;, set the pubspec to &lt;code&gt;sdk: ^3.11.0&lt;/code&gt; and &lt;code&gt;flutter: "&amp;gt;=3.41.0"&lt;/code&gt;, and point the podspec at the new paths. Flutter asks plugins to support both SwiftPM and CocoaPods until further notice, because as of 3.44 a plugin that drops CocoaPods can't be used by projects that haven't migrated.&lt;/p&gt;

&lt;h2&gt;
  
  
  React Native: experimental, and CocoaPods is still the supported path
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmeprlukepgbvb0o3a4lc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmeprlukepgbvb0o3a4lc.png" alt="A React Native phone leads to an iOS project folder with a Podfile, Podfile.lock and Xcode project. A solid path goes to CocoaPods, marked supported and stable. A dashed path goes to SwiftPM, marked experimental and opt-in. A five-step row says create a branch, test the SwiftPM path, verify the build and features, merge if stable, and roll back if needed." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;React Native 0.87, announced on 11 August 2026, added &lt;a href="https://reactnative.dev/blog/2026/08/11/react-native-0.87" rel="noopener noreferrer"&gt;experimental SwiftPM support for iOS&lt;/a&gt;. The post says it is opt-in and additive, that CocoaPods remains the default and supported path, and that the commands, flags and generated layout may change. Its last known-limitations line reads "Do not use it in production yet."&lt;/p&gt;

&lt;p&gt;React Native 0.88, announced on 19 October 2026, says &lt;a href="https://reactnative.dev/blog/2026/10/19/react-native-0.88" rel="noopener noreferrer"&gt;SwiftPM support remains experimental and opt-in&lt;/a&gt; while CocoaPods remains fully supported. It also states the plan: 0.89 targets SwiftPM as the default with an opt-out for apps that are still blocked, and a later release removes CocoaPods support. No date is given for that removal. The open &lt;a href="https://github.com/react-native-community/discussions-and-proposals/blob/f17ba71b4121cd9b56f56b561c4626579d943d58/proposals%2F0994-swift-package-manager-support-for-react-native-ios-projects.md" rel="noopener noreferrer"&gt;RFC&lt;/a&gt; says existing apps should not need to migrate immediately.&lt;/p&gt;

&lt;p&gt;So here is what is and isn't true today. The official environment setup page still lists CocoaPods as a requirement, and the existing-app guide still installs React Native with &lt;code&gt;bundle exec pod install&lt;/code&gt;. SwiftPM is available behind a command, and React Native itself says not to ship it yet.&lt;/p&gt;

&lt;p&gt;In August 2024 the CocoaPods maintainer wrote that for React Native a read-only trunk could be fine as it is, because most of its libraries come through npm and not trunk. React Native's own rn-tester app fits that picture: its &lt;a href="https://github.com/react/react-native/blob/main/packages/rn-tester/Podfile.lock" rel="noopener noreferrer"&gt;Podfile.lock&lt;/a&gt; lists two pods under trunk, OCMock and SocketRocket. Your app's lock file settles it for you, so run the command at the top of this post.&lt;/p&gt;

&lt;p&gt;The 0.87 post says a community library must ship a &lt;code&gt;Package.swift&lt;/code&gt;, and tells you to generate one from the podspec if it doesn't. The RFC adds that a library with its own manifest, in its root or in &lt;code&gt;ios/&lt;/code&gt;, is detected automatically. This lists your libraries that have a podspec but no manifest:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; d &lt;span class="k"&gt;in&lt;/span&gt; node_modules/* node_modules/@*/*&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt; -d &lt;span class="s2"&gt;"$d"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nb"&gt;continue&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; ls -d &lt;span class="s2"&gt;"$d"&lt;/span&gt;/*.podspec &lt;span class="s2"&gt;"$d"&lt;/span&gt;/ios/*.podspec 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null &lt;span class="o"&gt;|&lt;/span&gt; grep -q .&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -f &lt;span class="s2"&gt;"$d/Package.swift"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; -f &lt;span class="s2"&gt;"$d/ios/Package.swift"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
      &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Package.swift   $d"&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"podspec only    $d"&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;react-native&lt;/code&gt; package itself will appear in the list. Ignore it: the core is handled by React Native's own SwiftPM path.&lt;/p&gt;

&lt;p&gt;If you want to try the SwiftPM path, do it on a branch. These are the commands from the 0.87 post. Run them from &lt;code&gt;ios/&lt;/code&gt;, one at a time, depending on what you need.&lt;/p&gt;

&lt;p&gt;To move an app off CocoaPods (removes CocoaPods from the project and injects Swift package references):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ios
npx react-native spm --deintegrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To reverse the injection, run &lt;code&gt;npx react-native spm deinit&lt;/code&gt;. For a library that only has a podspec, run &lt;code&gt;npx react-native spm scaffold&lt;/code&gt; from the app root or from &lt;code&gt;ios/&lt;/code&gt;. The file is written into the library's folder in &lt;code&gt;node_modules&lt;/code&gt;, so keep it with patch-package until the library ships its own. That command can fail: on async-storage 3.1.1 it stopped with an error that the library mixes Swift and Objective-C, which Swift Package Manager cannot compile in a single target. After a fresh clone and in CI, run &lt;code&gt;npx react-native spm&lt;/code&gt;, the analog of &lt;code&gt;pod install&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The 0.87 post says the command injects package references into your existing &lt;code&gt;.xcodeproj&lt;/code&gt; and leaves signing, capabilities and build phases alone. To go back to CocoaPods after &lt;code&gt;--deintegrate&lt;/code&gt;, the RFC says to restore the Podfile from git and run &lt;code&gt;pod install&lt;/code&gt;. One breaking change to check for: React Native headers imported without a namespace need one, so &lt;code&gt;#import &amp;lt;RCTAppDelegate.h&amp;gt;&lt;/code&gt; becomes &lt;code&gt;#import &amp;lt;React/RCTAppDelegate.h&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;My position is that most React Native teams should run the inventory this week, try the SwiftPM path on a branch, and keep shipping on CocoaPods until React Native's own docs stop recommending it. Pods already published to trunk keep installing, so nothing forces your hand on 2 December.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pods that never ship SwiftPM
&lt;/h2&gt;

&lt;p&gt;Some of the names from step 1 will have no Package.swift and no sign of getting one. You have five options, and I'd go in this order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Replace it.&lt;/strong&gt; Swift.org suggests searching for an alternative so you don't end up with an unmaintained dependency. If the pod is abandoned anyway, this is the cheapest fix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep it on CocoaPods at the version you have.&lt;/strong&gt; Podfile.lock pins the exact version, and the CocoaPods guide says &lt;code&gt;pod install&lt;/code&gt; keeps installing that version unless you update it. If you need the pod to stop depending on trunk, point the Podfile at a Git tag or a local path. The podspec has to sit in that repository's root or folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="s1"&gt;'SomeLib'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:git&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'https://github.com/example/SomeLib.git'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:tag&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'1.2.3'&lt;/span&gt;
&lt;span class="n"&gt;pod&lt;/span&gt; &lt;span class="s1"&gt;'OtherLib'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:path&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'../vendor/OtherLib'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fork it and add a Package.swift.&lt;/strong&gt; Put the manifest in the root of your fork and tag a release with a full three-number version, then add the fork's URL in Xcode like any other package. SwiftPM's docs say that is what it expects. A Swift-only pod can be this small. For C or Objective-C sources, SwiftPM's docs say public headers go in a directory commonly named &lt;code&gt;include&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="c1"&gt;// swift-tools-version:5.9&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nc"&gt;PackageDescription&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;package&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Package&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SomeLib"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;platforms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;iOS&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;v13&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;library&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SomeLib"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;targets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"SomeLib"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;targets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;target&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SomeLib"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Classes"&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use a binary target.&lt;/strong&gt; If the vendor ships an XCFramework, or you can build one, wrap it in a package. Apple's docs say a binary target has to match the artifact's module name, a hosted one needs a ZIP with the XCFramework in its root plus a checksum, and binary targets only work on Apple platforms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;swift package compute-checksum path/to/SomeLib.zip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;binaryTarget&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"SomeLib"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://example.com/SomeLib.zip"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;checksum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"3a3cd2b9da90490cba4cc3c73a9e9323445b63f4aef529f4c80e4182190204d5"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your own manifest, use the value &lt;code&gt;compute-checksum&lt;/code&gt; printed for the ZIP you host. For a framework that lives in your own repository, &lt;code&gt;.binaryTarget(name:path:)&lt;/code&gt; takes the path to the XCFramework and needs no checksum.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vendor it into a local package.&lt;/strong&gt; Copy the source into a local Swift package in your repo, add a manifest, and add the package to your target. Apple's local packages guide shows File &amp;gt; New &amp;gt; Package, then adding the library product under Frameworks, Libraries, and Embedded Content. Check the license before you copy anything.&lt;/p&gt;

&lt;p&gt;If you only have time for one thing before 2 December, run the first command and commit the list with a Package.swift yes or no beside each name.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;CocoaPods Trunk Read-only Plan: &lt;a href="https://blog.cocoapods.org/CocoaPods-Specs-Repo/" rel="noopener noreferrer"&gt;https://blog.cocoapods.org/CocoaPods-Specs-Repo/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;CocoaPods Support &amp;amp; Maintenance Plans: &lt;a href="https://blog.cocoapods.org/CocoaPods-Support-Plans/" rel="noopener noreferrer"&gt;https://blog.cocoapods.org/CocoaPods-Support-Plans/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;What's new in Swift, November 2026: &lt;a href="https://www.swift.org/blog/whats-new-in-swift-november-2026/" rel="noopener noreferrer"&gt;https://www.swift.org/blog/whats-new-in-swift-november-2026/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Flutter, Swift Package Manager for app developers: &lt;a href="https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-app-developers" rel="noopener noreferrer"&gt;https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-app-developers&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Flutter, Swift Package Manager for plugin authors: &lt;a href="https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors" rel="noopener noreferrer"&gt;https://docs.flutter.dev/packages-and-plugins/swift-package-manager/for-plugin-authors&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Flutter tool source, plugins.dart: &lt;a href="https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/plugins.dart" rel="noopener noreferrer"&gt;https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/plugins.dart&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React Native 0.87: &lt;a href="https://reactnative.dev/blog/2026/08/11/react-native-0.87" rel="noopener noreferrer"&gt;https://reactnative.dev/blog/2026/08/11/react-native-0.87&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React Native 0.88: &lt;a href="https://reactnative.dev/blog/2026/10/19/react-native-0.88" rel="noopener noreferrer"&gt;https://reactnative.dev/blog/2026/10/19/react-native-0.88&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React Native RFC 0994: &lt;a href="https://github.com/react-native-community/discussions-and-proposals/pull/994" rel="noopener noreferrer"&gt;https://github.com/react-native-community/discussions-and-proposals/pull/994&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React Native rn-tester Podfile.lock: &lt;a href="https://github.com/react/react-native/blob/main/packages/rn-tester/Podfile.lock" rel="noopener noreferrer"&gt;https://github.com/react/react-native/blob/main/packages/rn-tester/Podfile.lock&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React Native, Set up your environment: &lt;a href="https://reactnative.dev/docs/set-up-your-environment" rel="noopener noreferrer"&gt;https://reactnative.dev/docs/set-up-your-environment&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;React Native, Integration with existing apps: &lt;a href="https://reactnative.dev/docs/integration-with-existing-apps" rel="noopener noreferrer"&gt;https://reactnative.dev/docs/integration-with-existing-apps&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple, Adding package dependencies to your app: &lt;a href="https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple, Distributing binary frameworks as Swift packages: &lt;a href="https://developer.apple.com/documentation/xcode/distributing-binary-frameworks-as-swift-packages" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcode/distributing-binary-frameworks-as-swift-packages&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple, Organizing your code with local packages: &lt;a href="https://developer.apple.com/documentation/xcode/organizing-your-code-with-local-packages" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcode/organizing-your-code-with-local-packages&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apple, Building Swift packages in continuous integration workflows: &lt;a href="https://developer.apple.com/documentation/xcode/building-swift-packages-or-apps-that-use-them-in-continuous-integration-workflows" rel="noopener noreferrer"&gt;https://developer.apple.com/documentation/xcode/building-swift-packages-or-apps-that-use-them-in-continuous-integration-workflows&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SwiftPM, Releasing and publishing a Swift package: &lt;a href="https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackageManagerDocs/Documentation.docc/ReleasingPublishingAPackage.md" rel="noopener noreferrer"&gt;https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackageManagerDocs/Documentation.docc/ReleasingPublishingAPackage.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;SwiftPM, Creating C language targets: &lt;a href="https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackageManagerDocs/Documentation.docc/CreatingCLanguageTargets.md" rel="noopener noreferrer"&gt;https://github.com/swiftlang/swift-package-manager/blob/main/Sources/PackageManagerDocs/Documentation.docc/CreatingCLanguageTargets.md&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;CocoaPods guides, Podfile syntax, commands and using CocoaPods: &lt;a href="https://guides.cocoapods.org/syntax/podfile.html" rel="noopener noreferrer"&gt;https://guides.cocoapods.org/syntax/podfile.html&lt;/a&gt;, &lt;a href="https://guides.cocoapods.org/terminal/commands.html" rel="noopener noreferrer"&gt;https://guides.cocoapods.org/terminal/commands.html&lt;/a&gt;, &lt;a href="https://guides.cocoapods.org/using/using-cocoapods.html" rel="noopener noreferrer"&gt;https://guides.cocoapods.org/using/using-cocoapods.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ios</category>
      <category>swift</category>
      <category>flutter</category>
      <category>reactnative</category>
    </item>
    <item>
      <title>The Startup Crashes Your Kill Switch Never Sees</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Mon, 23 Nov 2026 10:27:48 +0000</pubDate>
      <link>https://dev.to/prikshit/the-startup-crashes-your-kill-switch-never-sees-2942</link>
      <guid>https://dev.to/prikshit/the-startup-crashes-your-kill-switch-never-sees-2942</guid>
      <description>&lt;p&gt;&lt;em&gt;A Room migration or a missing R8 keep rule can put an Android app in a crash loop before Remote Config loads. A flag can't reach that code, so tests and a startup guard have to.&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"...once an app has the bad configuration it will continue to crash before it's able to successfully fetch the corrected configuration."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Lyft's engineers &lt;a href="https://eng.lyft.com/recovering-from-crashes-with-safe-mode-77ff572fdfda" rel="noopener noreferrer"&gt;wrote that in 2022&lt;/a&gt; about feature flags that crashed their app at launch. Turning the flag off remotely didn't help, and they usually had to ship a hotfix. Their answer was Safe Mode, which locks the flags read before a launch crash to their local defaults for the rest of the session. The post's list of future work ends on a question: what other things cause crash loops on launch?&lt;/p&gt;

&lt;p&gt;My &lt;a href="https://dev.to/prikshit/mobile-apps-cant-roll-back-so-agent-written-code-needs-a-release-gate-4ole"&gt;release gate piece&lt;/a&gt; ended its checklist with one line about the code no flag can reach: startup code, database migrations, manifest changes and R8 keep rules. A reader pointed out under a recent post that an unverified Room migration in &lt;code&gt;Application.onCreate()&lt;/code&gt; crash-loops before a Remote Config flag is even evaluated. That's right, and one line wasn't enough. This is the longer version for Android, covering Room migrations and R8 keep rules, with the tests and guards that belong in front of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  A flag only works if the code asks for it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhxkpkha9bs6gbv9f22u0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhxkpkha9bs6gbv9f22u0.png" alt="Card titled When can a flag help? It has three rows. Early startup: a provider or initializer can fail before the launcher Activity. Cached values: a flag can affect code that reaches the check and reads it. Remote correction: a new value can help once the app fetches and activates it." width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Android calls &lt;code&gt;Application.onCreate()&lt;/code&gt; "when the application is starting, before any activity, service, or receiver objects (excluding content providers) have been created" (&lt;a href="https://developer.android.com/reference/android/app/Application" rel="noopener noreferrer"&gt;Application reference&lt;/a&gt;). Content providers come first. That includes &lt;a href="https://developer.android.com/topic/libraries/app-startup" rel="noopener noreferrer"&gt;App Startup&lt;/a&gt;, which runs its initializers through a single &lt;code&gt;InitializationProvider&lt;/code&gt;, and any library that starts itself the same way.&lt;/p&gt;

&lt;p&gt;Remote Config doesn't fit inside that window. &lt;code&gt;fetchAndActivate()&lt;/code&gt; returns a &lt;code&gt;Task&lt;/code&gt; that finishes whenever the network call does, and the &lt;a href="https://firebase.google.com/docs/remote-config/android/get-started" rel="noopener noreferrer"&gt;Android guide&lt;/a&gt; says the default minimum fetch interval is 12 hours, so configs "won't be fetched from the backend more than once in a 12 hour window, regardless of how many fetch calls are actually made." The &lt;a href="https://firebase.google.com/docs/remote-config/loading" rel="noopener noreferrer"&gt;loading strategies guide&lt;/a&gt; describes a pattern where the app activates values fetched in an earlier session right away, then fetches new ones in the background for the next startup. In a crash loop the process often dies before that background fetch finishes, and inside the 12-hour window the fetch may not reach the backend at all. Real-time updates skip the interval, but only once the listener is running.&lt;/p&gt;

&lt;p&gt;The obvious answer is to block startup on a fetch with a short timeout. Firebase's own Strategy 2 does that behind a loading screen, and it's reasonable for A/B tests. Lyft considered a forced refresh for crash loops and turned it down for two reasons, paraphrased here from the post. A forced refresh would have kept users out of the app until someone reverted the bad change, and the network call needed extra dependencies set up first, which had themselves caused launch crashes before.&lt;/p&gt;

&lt;p&gt;On Android, two causes deserve a release rule of their own, and neither one reads a flag.&lt;/p&gt;

&lt;h2&gt;
  
  
  Room runs migrations when it opens the database
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fknax8ob90iymew36x5ks.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fknax8ob90iymew36x5ks.png" alt="Card titled Rolling back code with Room. It has three rows. On disk: the bad release has already migrated the database to v24. Pure code revert: code expecting v23 needs a migration from 24 to 23 to open it. Forward compatible rollback: keep schema v24, or migrate forward to restore the old shape." width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Builder" rel="noopener noreferrer"&gt;&lt;code&gt;RoomDatabase.Builder&lt;/code&gt; reference&lt;/a&gt; says that when the version on the device doesn't match the latest schema, Room runs the migrations, and "if it cannot find the set of Migrations that will bring the database to the current version, it will throw an IllegalStateException." The &lt;a href="https://developer.android.com/training/data-storage/room/migrating-db-versions" rel="noopener noreferrer"&gt;migration guide&lt;/a&gt; adds that "an incorrectly defined migration can cause your app to crash."&lt;/p&gt;

&lt;p&gt;Where that crash lands depends on where your first query sits. If it runs from &lt;code&gt;Application.onCreate()&lt;/code&gt; or an App Startup initializer, the crash comes before the first screen draws. Moving the open later doesn't stop the crash in an app whose first screen reads the database. It just gives your own code a chance to run first. And nothing changes before the next launch. The file on disk is at the old version, the code still has no path from it, so Room throws again.&lt;/p&gt;

&lt;p&gt;Android's own &lt;a href="https://developer.android.com/reference/android/content/ContentProvider" rel="noopener noreferrer"&gt;&lt;code&gt;ContentProvider.onCreate()&lt;/code&gt; docs&lt;/a&gt; already warn about this kind of startup work. They say to defer "opening, upgrading, and scanning databases" until the provider is used, partly because deferring "stops database errors (such as a full disk) from halting application launch." The same reasoning fits any code on the startup path.&lt;/p&gt;

&lt;p&gt;Wrapping the database open in a flag doesn't help either. Room doesn't consult Remote Config before it migrates, and an app that can't open its database while the flag is off can't show the user their data.&lt;/p&gt;

&lt;p&gt;There's also a catch in the rollback from the release gate piece, which was re-shipping the previous code under a higher version code. If the bad build already migrated someone's database to a newer version, the old code arrives at a database newer than it knows about, and Room needs a migration going down. This is what that looks like, from a &lt;a href="https://github.com/KotatsuApp/Kotatsu/issues/1268" rel="noopener noreferrer"&gt;public bug report&lt;/a&gt; on Kotatsu, an open-source Android app, where the app displayed it right after opening:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A migration from 24 to 23 was required but not found. Please provide the necessary Migration path via RoomDatabase.Builder.addMigration(Migration ...) or allow for destructive migrations via one of the RoomDatabase.Builder.fallbackToDestructiveMigration* methods.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A database at version 24 and code expecting 23. &lt;code&gt;fallbackToDestructiveMigrationOnDowngrade&lt;/code&gt; gets past it by dropping and recreating the tables, which deletes all of the user's data. The safer rollback never goes down. The rollback build keeps the &lt;code&gt;@Database&lt;/code&gt; version and schema the bad build shipped, or moves one version higher with a migration back to the old shape, so Room only ever migrates forward and the user keeps their rows. That makes the rollback something other than a pure revert of the code.&lt;/p&gt;

&lt;p&gt;The guide's warning about &lt;code&gt;fallbackToDestructiveMigration&lt;/code&gt; is just as blunt: Room "permanently deletes all data from the tables in the user's database" when it falls back. My opinion is that it shouldn't go into a production builder just to stop a crash. A crash loop at least shows up in your crash reports and in &lt;a href="https://developer.android.com/topic/performance/vitals" rel="noopener noreferrer"&gt;Android vitals&lt;/a&gt;. Wiped tables don't show up in either one. You can log one through &lt;a href="https://developer.android.com/reference/kotlin/androidx/room/RoomDatabase.Callback" rel="noopener noreferrer"&gt;&lt;code&gt;RoomDatabase.Callback.onDestructiveMigration()&lt;/code&gt;&lt;/a&gt;, but by then the data is already gone. If one old version really can't be migrated, &lt;code&gt;fallbackToDestructiveMigrationFrom&lt;/code&gt; limits the loss to that version, and that choice deserves a named reviewer. (Since Room 2.7 these builder functions take a &lt;code&gt;dropAllTables&lt;/code&gt; argument, and the no-argument versions are deprecated.)&lt;/p&gt;

&lt;h2&gt;
  
  
  R8 misses only exist in the build you ship
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcwl3o2x8du7aacvi72nq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcwl3o2x8du7aacvi72nq.png" alt="Card titled Where the plugin disappears. It has three rows. Debug build: the class name in a resource resolves at runtime. Minified release: R8 can rename or remove a class reached through reflection. Release check: keep the class and its constructor, then launch the minified build." width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.android.com/topic/performance/app-optimization/enable-app-optimization" rel="noopener noreferrer"&gt;R8&lt;/a&gt; removes code it thinks is unused and shortens class, field and method names. Google recommends turning it on only for the final build you test before publishing, which is usually the release build. Follow that advice and your debug builds never run R8's output.&lt;/p&gt;

&lt;p&gt;The trouble is code R8 can't see being used. The &lt;a href="https://developer.android.com/topic/performance/app-optimization/keep-rules-overview" rel="noopener noreferrer"&gt;keep rules overview&lt;/a&gt; names reflection, such as a method looked up by name with &lt;code&gt;Class.getDeclaredMethod()&lt;/code&gt;, and calls across JNI. R8 can rename or remove those targets, "leading to a ClassNotFoundException or a NoSuchMethodException at runtime." Since AGP 8.0, R8 runs in full mode by default, which the R8 page says makes "stricter assumptions about how your code uses reflection" and might need extra keep rules.&lt;/p&gt;

&lt;p&gt;R8 can't follow this pattern. Optional modules list their startup plugins by class name in a string-array resource, and the app builds them at launch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;StartupPlugin&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;install&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Optional modules list their class names in a string-array resource,&lt;/span&gt;
&lt;span class="c1"&gt;// so the core app never references them directly.&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;installStartupPlugins&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;classNames&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;String&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;classNames&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;plugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDeclaredConstructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;StartupPlugin&lt;/span&gt;
        &lt;span class="n"&gt;plugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;install&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A debug build runs this fine. In a minified build, nothing in the code names those plugin classes, so R8 can remove or rename them, and &lt;code&gt;Class.forName&lt;/code&gt; throws &lt;code&gt;ClassNotFoundException&lt;/code&gt;. If &lt;code&gt;installStartupPlugins&lt;/code&gt; runs from &lt;code&gt;Application.onCreate()&lt;/code&gt;, it throws on every launch. R8's &lt;a href="https://r8.googlesource.com/r8/+/refs/heads/main/compatibility-faq.md" rel="noopener noreferrer"&gt;compatibility FAQ&lt;/a&gt; says classes "only instantiated using reflection should be kept explicitly with a &lt;code&gt;-keep&lt;/code&gt; rule," and that in full mode keeping a class doesn't keep its default constructor, which is why the rule names &lt;code&gt;&amp;lt;init&amp;gt;()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# proguard-rules.pro (with AGP 9.3's new DSL: src/main/keepRules/startup.keep)
-keep class * implements com.example.startup.StartupPlugin {
    &amp;lt;init&amp;gt;();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No flag can reach this one. The code is missing from the APK, and a keep rule only takes effect in a new build. If your own code does the reflection, &lt;a href="https://developer.android.com/topic/performance/app-optimization/jetpack-keep-annotations" rel="noopener noreferrer"&gt;Jetpack Keep&lt;/a&gt; lets you annotate the call instead of maintaining rules by hand, and its lint checks flag reflective calls you didn't annotate. It's still in alpha, so compare the generated rules when you upgrade it.&lt;/p&gt;

&lt;p&gt;Google's &lt;a href="https://developer.android.com/topic/performance/app-optimization/test-the-optimization" rel="noopener noreferrer"&gt;Test the optimization&lt;/a&gt; page says keep rules on rarely used code "can be difficult to test" locally, and suggests staged rollouts while you watch for crash regressions. Startup code is the opposite of rarely used, though. Every user runs it on every launch, so one launch of the minified build catches it before a user does. Two notes from the &lt;a href="https://developer.android.com/topic/performance/app-optimization/test-and-troubleshoot-the-optimization" rel="noopener noreferrer"&gt;troubleshooting page&lt;/a&gt; also matter. &lt;code&gt;mapping.txt&lt;/code&gt; is bundled into your app bundle, so Play gets it, but the local file is overwritten on every build, so keep a copy per release for &lt;code&gt;retrace&lt;/code&gt; and for any crash tool that doesn't read it from the bundle. And &lt;code&gt;app/build/outputs/mapping/configuration.txt&lt;/code&gt; lists every merged rule, including the ones your libraries add.&lt;/p&gt;

&lt;h2&gt;
  
  
  The checklist
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd731dicxuf32m6lix22h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd731dicxuf32m6lix22h.png" alt="Card titled Six checks before a wider rollout. 1, export schemas and commit the JSON history. 2, share one migration list between the app and its tests. 3, start from every shipped schema and verify moved rows. 4, guard startup by counting failed user launches. 5, install the candidate over the previous build with data intact. 6, compare crash rates by build before expanding." width="800" height="594"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code below uses Room 2.8.5 (&lt;code&gt;androidx.room&lt;/code&gt;) with AGP 8.13.2, Gradle 8.14.3, Kotlin 2.2.21 and KSP 2.2.21-2.0.5, and the runtime checks ran on an API 35 emulator. On &lt;a href="https://developer.android.com/build/releases/agp-9-3-0-release-notes" rel="noopener noreferrer"&gt;AGP 9.3&lt;/a&gt; you need Gradle 9.5.0 or newer, you drop the &lt;code&gt;org.jetbrains.kotlin.android&lt;/code&gt; plugin because &lt;a href="https://developer.android.com/build/migrate-to-built-in-kotlin" rel="noopener noreferrer"&gt;Kotlin is built in&lt;/a&gt;, and you need KSP 2.3.14 or newer, since the 2.2.21 line of KSP refuses to run with built-in Kotlin. Room 3.0 moved to &lt;code&gt;androidx.room3&lt;/code&gt;, and the current migration guide shows that version. The same approach applies to both, but on Room 3 the open and test calls go through the driver (&lt;code&gt;SQLiteConnection&lt;/code&gt;) instead of &lt;code&gt;openHelper&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Export schemas and commit them.&lt;/strong&gt; The guide says to keep the exported JSON in version control "so that you can recreate lower versions of the database for testing." The folder also collects schemas from development builds that never shipped, and step 3 has to know about those. The same Gradle file adds a release copy that CI can install, signed with the debug key the way the &lt;a href="https://developer.android.com/topic/performance/benchmarking/macrobenchmark-overview" rel="noopener noreferrer"&gt;Macrobenchmark setup&lt;/a&gt; does it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// app/build.gradle.kts (excerpt, AGP 8.x legacy DSL)&lt;/span&gt;
&lt;span class="n"&gt;plugins&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"com.android.application"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"org.jetbrains.kotlin.android"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// not needed on AGP 9.x, which has built-in Kotlin&lt;/span&gt;
    &lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"com.google.devtools.ksp"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.room"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;android&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;buildFeatures&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;buildConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;buildTypes&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;getByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"release"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;isMinifyEnabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
            &lt;span class="n"&gt;isShrinkResources&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
            &lt;span class="nf"&gt;proguardFiles&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="nf"&gt;getDefaultProguardFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"proguard-android-optimize.txt"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="s2"&gt;"proguard-rules.pro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c1"&gt;// Same R8 setup as release, signed with the debug key so CI can install it.&lt;/span&gt;
        &lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"releaseCheck"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;initWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"release"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;signingConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;signingConfigs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"debug"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;matchingFallbacks&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nf"&gt;listOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"release"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;room&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;schemaDirectory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"$projectDir/schemas"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;implementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.room:room-runtime:2.8.5"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;ksp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.room:room-compiler:2.8.5"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;androidTestImplementation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"androidx.room:room-testing:2.8.5"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Keep one list of migrations.&lt;/strong&gt; The app's builder and the test read the same array, so a migration added in one place is in the other.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@Database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Note&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AppDatabase&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;RoomDatabase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;noteDao&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;NoteDao&lt;/span&gt;

    &lt;span class="n"&gt;companion&lt;/span&gt; &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;@Volatile&lt;/span&gt; &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AppDatabase&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;

        &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AppDatabase&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
            &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="k"&gt;synchronized&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;databaseBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;applicationContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="nc"&gt;AppDatabase&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="s2"&gt;"app.db"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addMigrations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="no"&gt;ALL_MIGRATIONS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;also&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;instance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// One list, read by the app's builder and by the migration test.&lt;/span&gt;
&lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;ALL_MIGRATIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;arrayOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MIGRATION_1_2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;MIGRATION_2_3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Test an upgrade from every shipped version.&lt;/strong&gt; The guide recommends a test that covers all migrations from the earliest version. This one starts from each exported schema in turn, because a user who skipped five releases walks a different chain than someone who updated last week. A schema that only existed on a branch may have no path to latest and would then fail the loop. List it in &lt;code&gt;neverShipped&lt;/code&gt; instead of writing a migration for a version nobody ever had.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="nd"&gt;@RunWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AndroidJUnit4&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ShippedSchemasMigrationTest&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;instrumentation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;InstrumentationRegistry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstrumentation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nd"&gt;@get&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nc"&gt;Rule&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;helper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MigrationTestHelper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;instrumentation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;AppDatabase&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;// Schemas exported during development that no release ever shipped,&lt;/span&gt;
    &lt;span class="c1"&gt;// for example setOf(5) if version 5 only lived on a branch.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;neverShipped&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;emptySet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;Int&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nd"&gt;@Test&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;everyExportedSchemaUpgradesToLatest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Exported schemas land in test assets as &amp;lt;database class&amp;gt;/&amp;lt;version&amp;gt;.json.&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;versions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;instrumentation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;assets&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AppDatabase&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;canonicalName&lt;/span&gt;&lt;span class="o"&gt;!!&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!!&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeSuffix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;".json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nf"&gt;assertTrue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"No older schemas found in test assets"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;versions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;versions&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dropLast&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;neverShipped&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"upgrade-from-$version"&lt;/span&gt;
            &lt;span class="n"&gt;helper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createDatabase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;close&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Room&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;databaseBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="n"&gt;instrumentation&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;targetContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nc"&gt;AppDatabase&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addMigrations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="no"&gt;ALL_MIGRATIONS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;helper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;closeWhenFinished&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="c1"&gt;// Opening runs every migration from `version` and validates the final schema.&lt;/span&gt;
            &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;openHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;writableDatabase&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This test checks schemas. For migrations that move rows around, also keep a single-version test that inserts rows at the old version and reads them back after &lt;code&gt;runMigrationsAndValidate&lt;/code&gt;, as the guide shows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Add a startup crash guard.&lt;/strong&gt; Crash reporters already expose the raw signal. BugSnag's &lt;a href="https://docs.bugsnag.com/platforms/android/identifying-crashes-at-launch/" rel="noopener noreferrer"&gt;launch crash docs&lt;/a&gt; describe &lt;code&gt;crashedDuringLaunch&lt;/code&gt; and &lt;code&gt;consecutiveLaunchCrashes&lt;/code&gt;, and Crashlytics has &lt;a href="https://firebase.google.com/docs/reference/android/com/google/firebase/crashlytics/FirebaseCrashlytics" rel="noopener noreferrer"&gt;&lt;code&gt;didCrashOnPreviousExecution()&lt;/code&gt;&lt;/a&gt;, which reports any crash on the previous run. A small counter does the job without either.&lt;/p&gt;

&lt;p&gt;The counter has to count the right thing. &lt;code&gt;Application.onCreate()&lt;/code&gt; runs for every process start, including a push message, a WorkManager job or a broadcast receiver, and none of those reach your first screen. Count there and two background wakes put a healthy user into safe mode. So this guard counts only fresh launches of the launcher Activity. On Android 11 and later it also asks the OS how the last launch ended. &lt;a href="https://developer.android.com/reference/android/app/ActivityManager" rel="noopener noreferrer"&gt;&lt;code&gt;ActivityManager.getHistoricalProcessExitReasons()&lt;/code&gt;&lt;/a&gt; returns recent &lt;a href="https://developer.android.com/reference/android/app/ApplicationExitInfo" rel="noopener noreferrer"&gt;&lt;code&gt;ApplicationExitInfo&lt;/code&gt;&lt;/a&gt; records, and &lt;code&gt;REASON_CRASH&lt;/code&gt; ("died because of an unhandled exception in Java code") is a different reason from &lt;code&gt;REASON_USER_REQUESTED&lt;/code&gt;, which the docs say covers swiping the app away from Recents. The helper below counts &lt;code&gt;REASON_CRASH&lt;/code&gt;, &lt;code&gt;REASON_CRASH_NATIVE&lt;/code&gt;, &lt;code&gt;REASON_ANR&lt;/code&gt; and &lt;code&gt;REASON_EXCESSIVE_RESOURCE_USAGE&lt;/code&gt; as failed launches. The last one is there because, on an API 35 emulator, a second crash within about a minute left the process behind the "keeps stopping" dialog (nobody dismissed it, as in CI), and the system later killed it for excessive resource use instead of recording a crash. Counting &lt;code&gt;REASON_ANR&lt;/code&gt; also catches a launch that hangs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Android 11+ keeps a short history of why the app's processes died.&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;Context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;crashedSince&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sinceMillis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Long&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;VERSION&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;SDK_INT&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;VERSION_CODES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;am&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getSystemService&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;ActivityManager&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;am&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getHistoricalProcessExitReasons&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;any&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;timestamp&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;sinceMillis&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
            &lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reason&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="no"&gt;FAILED_LAUNCH_EXITS&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// A process that crashes again soon after a crash can sit behind the "keeps stopping"&lt;/span&gt;
&lt;span class="c1"&gt;// dialog and be killed later for excessive resource use, so that reason counts too.&lt;/span&gt;
&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;FAILED_LAUNCH_EXITS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationExitInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;REASON_CRASH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationExitInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;REASON_CRASH_NATIVE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationExitInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;REASON_ANR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;ApplicationExitInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;REASON_EXCESSIVE_RESOURCE_USAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It writes with &lt;code&gt;commit()&lt;/code&gt; because the &lt;a href="https://developer.android.com/reference/android/content/SharedPreferences.Editor" rel="noopener noreferrer"&gt;SharedPreferences docs&lt;/a&gt; say &lt;code&gt;apply()&lt;/code&gt; only "starts an asynchronous commit to disk," and this state has to be on disk before the risky code runs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StartupGuard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;SharedPreferences&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;versionCode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Long&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// true or false on Android 11+, null on older versions where the OS can't say.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;crashedSince&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Long&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;maxFailedLaunches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/** Call from the launcher Activity, once per fresh user launch. Returns true for safe mode. */&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onUserLaunch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;nowMillis&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Long&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;currentTimeMillis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;sameBuild&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLong&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_VERSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1L&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;versionCode&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;failed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sameBuild&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_FAILED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;lastUnfinished&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sameBuild&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_UNFINISHED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;// An unfinished launch counts unless the OS says it didn't end in a crash.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lastUnfinished&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;crashedSince&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLong&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_STARTED_AT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0L&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;failed&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="c1"&gt;// A small synchronous write on purpose: it has to reach disk before risky startup work runs.&lt;/span&gt;
        &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putLong&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_VERSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;versionCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_FAILED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;failed&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putLong&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_STARTED_AT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nowMillis&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putBoolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_UNFINISHED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;failed&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;maxFailedLaunches&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/** Call when the first screen is up and startup work has finished. Also backs "try again". */&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onLaunchCompleted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_FAILED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;putBoolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_UNFINISHED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/** For workers, receivers and other entry points: skip database work while this is true. */&lt;/span&gt;
    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;isInSafeMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Boolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLong&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_VERSION&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1L&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;versionCode&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;
            &lt;span class="n"&gt;prefs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;KEY_FAILED&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;maxFailedLaunches&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;companion&lt;/span&gt; &lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;KEY_VERSION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"version_code"&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;KEY_FAILED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"failed_launches"&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;KEY_STARTED_AT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"last_launch_started_at"&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;KEY_UNFINISHED&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"last_launch_unfinished"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then wire it so the database opens inside the guarded window. If the open on &lt;code&gt;Dispatchers.IO&lt;/code&gt; throws, &lt;code&gt;withContext&lt;/code&gt; rethrows into the coroutine on the main thread, so the crash shows up as &lt;code&gt;FATAL EXCEPTION: main&lt;/code&gt;. A failed migration now counts as a failed launch, and after two of those the app comes up in safe mode instead of crashing a third time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// No launch counting here: this runs for every process start, including&lt;/span&gt;
    &lt;span class="c1"&gt;// push messages, WorkManager jobs and broadcast receivers.&lt;/span&gt;
    &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;startupGuard&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;StartupGuard&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="kd"&gt;lazy&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;StartupGuard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;prefs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getSharedPreferences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"startup_guard"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;MODE_PRIVATE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;versionCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BuildConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;VERSION_CODE&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLong&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;crashedSince&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;since&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;crashedSince&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;since&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MainActivity&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ComponentActivity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bundle&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;guard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;application&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;App&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;startupGuard&lt;/span&gt;

        &lt;span class="c1"&gt;// Count fresh launches only, not rotation or restore after process death.&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;safeMode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onUserLaunch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isInSafeMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;safeMode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;setContent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;SafeModeScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;onTryAgain&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onLaunchCompleted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="nf"&gt;startActivity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Intent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;@&lt;span class="nc"&gt;MainActivity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;MainActivity&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;java&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="nf"&gt;finish&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;setContent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;AppContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;lifecycleScope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;launch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Risky startup work runs inside the guarded window, so a failed&lt;/span&gt;
            &lt;span class="c1"&gt;// migration counts as a failed launch.&lt;/span&gt;
            &lt;span class="nf"&gt;withContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Dispatchers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;IO&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;AppDatabase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getInstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;applicationContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;openHelper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;writableDatabase&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="n"&gt;guard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onLaunchCompleted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In safe mode the first screen skips optional work and keeps the database closed. It can still start Play's &lt;a href="https://developer.android.com/guide/playcore/in-app-updates" rel="noopener noreferrer"&gt;immediate in-app update&lt;/a&gt; once the fixed build is out, and "try again" clears the count and starts a fresh launch. If the bug is still there, one tap allows two more crashes before safe mode comes back. The count resets when the version code changes, so the fixed build starts clean.&lt;/p&gt;

&lt;p&gt;The guard has limits. Other entry points (a worker, a receiver, a deep link into a different Activity) still open the database on their own, so they should check &lt;code&gt;isInSafeMode()&lt;/code&gt; and skip that work, for example by returning &lt;code&gt;Result.retry()&lt;/code&gt; from a worker. Crashes before the launcher Activity, in &lt;code&gt;Application.onCreate()&lt;/code&gt;, a content provider or an App Startup initializer, never reach the counter, which is one more reason to keep risky work out of those places. Moving the count into &lt;code&gt;Application.attachBaseContext()&lt;/code&gt; would see them, since &lt;a href="https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/app/ActivityThread.java" rel="noopener noreferrer"&gt;AOSP's &lt;code&gt;handleBindApplication&lt;/code&gt;&lt;/a&gt; creates the Application (which calls &lt;code&gt;attachBaseContext()&lt;/code&gt;) before it installs content providers, but that runs for background process starts too. Before Android 11, a swipe during launch still counts as a failure, so tune the threshold from your own crash data. And ship it quietly first. Lyft rolled Safe Mode out with a "shadow" setting that only logged, and after shipping found it engaging at low volume on an unrelated thread-safety bug at launch.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Launch the minified build on top of the last release.&lt;/strong&gt; This runs in CI on an emulator, using the &lt;code&gt;releaseCheck&lt;/code&gt; type from step 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;
&lt;span class="c"&gt;# Upgrade smoke test: install the last release, then this build over it.&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail
&lt;span class="nv"&gt;PKG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;com.example.app
&lt;span class="nv"&gt;APK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;app/build/outputs/apk/releaseCheck/app-releaseCheck.apk

launch_and_check&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  adb logcat -b all -c   &lt;span class="c"&gt;# clear every buffer, including old crashes&lt;/span&gt;
  adb shell am start -W -S -n &lt;span class="s2"&gt;"$PKG/.MainActivity"&lt;/span&gt;  &lt;span class="c"&gt;# -S force-stops it first&lt;/span&gt;
  sleep 10  &lt;span class="c"&gt;# give startup work and the database open time to finish&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; adb logcat -b crash -d &lt;span class="o"&gt;|&lt;/span&gt; grep -q &lt;span class="s2"&gt;"$PKG"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
    adb logcat -b crash -d
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Startup crash: $1"&lt;/span&gt;
    &lt;span class="nb"&gt;exit&lt;/span&gt; 1
  &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

adb uninstall &lt;span class="s2"&gt;"$PKG"&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

git checkout &lt;span class="s2"&gt;"$LAST_RELEASE_TAG"&lt;/span&gt;
./gradlew :app:assembleReleaseCheck
adb install &lt;span class="s2"&gt;"$APK"&lt;/span&gt;
launch_and_check &lt;span class="s2"&gt;"last release"&lt;/span&gt;

git checkout &lt;span class="s2"&gt;"$CANDIDATE_SHA"&lt;/span&gt;
./gradlew :app:assembleReleaseCheck
adb install -r &lt;span class="s2"&gt;"$APK"&lt;/span&gt;   &lt;span class="c"&gt;# -r keeps the app's data, so the real upgrade runs&lt;/span&gt;
launch_and_check &lt;span class="s2"&gt;"candidate, first launch"&lt;/span&gt;
launch_and_check &lt;span class="s2"&gt;"candidate, second launch"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://developer.android.com/tools/adb" rel="noopener noreferrer"&gt;&lt;code&gt;adb install -r&lt;/code&gt;&lt;/a&gt; reinstalls "keeping its data," so the candidate opens a database the last release created and has to migrate it. The same launch runs R8's output, which a debug build and most unit tests never touch. It works from the first release that includes &lt;code&gt;releaseCheck&lt;/code&gt;. Until then, cherry-pick the build type onto the last release tag. It also only covers the newest upgrade path on a nearly empty database, so it's a check on startup code and R8. Step 3 covers older schemas, and the single-version test covers rows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Give these changes the slowest rollout, and name what you wait for.&lt;/strong&gt; Halting a Play staged rollout means "no additional users will receive the app version," and users who already got it "will remain on that version" (&lt;a href="https://support.google.com/googleplay/android-developer/answer/6346149" rel="noopener noreferrer"&gt;Play Console Help&lt;/a&gt;). A small first step still strands that small group, so it only helps if you're watching the right number. For startup changes, that's crash-free users and sessions for the new build in &lt;a href="https://firebase.google.com/docs/crashlytics/crash-free-metrics" rel="noopener noreferrer"&gt;Crashlytics&lt;/a&gt;, which you can filter by build, or the user-perceived crash rate per version code from the &lt;a href="https://developers.google.com/play/developer/reporting/reference/rest/v1beta1/vitals.crashrate" rel="noopener noreferrer"&gt;Play Developer Reporting API&lt;/a&gt;. Vitals comes from users who &lt;a href="https://support.google.com/googleplay/android-developer/answer/9844486" rel="noopener noreferrer"&gt;opted in&lt;/a&gt; to share usage and diagnostics data, and the API reports its own &lt;code&gt;freshnessInfo&lt;/code&gt;, so check which period the data actually covers before you expand. A diff that touches the &lt;code&gt;@Database&lt;/code&gt; version, a &lt;code&gt;Migration&lt;/code&gt;, startup code in &lt;code&gt;Application.onCreate()&lt;/code&gt; or an initializer, or a keep rules file waits at the first step until that number is steady against the previous build. If a coding agent wrote that diff, a human reviews those files no matter how small the change looks.&lt;/p&gt;

&lt;p&gt;This post sticks to Android. iOS has its own versions of startup work and data migrations, and App Store &lt;a href="https://developer.apple.com/help/app-store-connect/update-your-app/release-a-version-update-in-phases" rel="noopener noreferrer"&gt;phased release&lt;/a&gt; only limits automatic updates, since anyone can download the update manually at any time.&lt;/p&gt;

&lt;p&gt;Flags still earn their place for the code that reads them. Everything on this list runs earlier than that, so it has to be proven before the release starts.&lt;/p&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>mobile</category>
      <category>devops</category>
    </item>
    <item>
      <title>Gemini Accepted "thinkingBudget: 0". So Why Was It Still Thinking?</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Tue, 17 Nov 2026 14:57:26 +0000</pubDate>
      <link>https://dev.to/prikshit/gemini-accepted-thinkingbudget-0-so-why-was-it-still-thinking-24k4</link>
      <guid>https://dev.to/prikshit/gemini-accepted-thinkingbudget-0-so-why-was-it-still-thinking-24k4</guid>
      <description>&lt;p&gt;&lt;em&gt;An unexpected Gemini API result, a small experiment with reasoning tokens, and a lesson about verifying LLM behavior before production.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. The Unexpected Result
&lt;/h2&gt;

&lt;p&gt;Imagine configuring an AI model to minimize its reasoning effort. You set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"thinkingConfig"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"thinkingBudget"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your expectation is simple: either the model accepts the setting and behaves accordingly, or the API rejects it.&lt;/p&gt;

&lt;p&gt;But what happens when the request succeeds and the model still spends more than a thousand thinking tokens?&lt;/p&gt;

&lt;p&gt;That is what a small Gemini API experiment showed.&lt;/p&gt;

&lt;p&gt;The Firebase AI Logic thinking docs say that Gemini 4.x models do not support thinking budget and "will return a 400 error if it's set". The Firebase release note for gemini-4-hydrogen says the same: "thinkingBudget is not supported (there's no backwards-compatibility; the request will fail with a 400 error)."&lt;/p&gt;

&lt;p&gt;Yet a REST test against the Gemini Developer API, using &lt;code&gt;gemini-4-hydrogen&lt;/code&gt;, returned HTTP 200 for budgets of 0, 1024 and 8192.&lt;/p&gt;

&lt;p&gt;Even more interesting: &lt;code&gt;thinkingBudget: 0&lt;/code&gt; still produced 1,290 to 1,466 thinking tokens.&lt;/p&gt;

&lt;p&gt;Before calling this a bug, one distinction matters. Firebase AI Logic and the raw Developer API REST interface are different integration paths, and a statement written for one SDK does not automatically describe every endpoint.&lt;/p&gt;

&lt;p&gt;Still, the result raises a useful engineering question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does a successful API request mean our model configuration is actually doing what we intended?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not necessarily.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Understanding Thinking Tokens
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6lye5i5vrlsc2n0chli4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6lye5i5vrlsc2n0chli4.png" alt="Diagram: prompt, hidden thinking tokens, answer; thoughtsTokenCount plus candidatesTokenCount drive cost and latency" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reasoning-capable language models can spend tokens on internal computation before producing the visible answer. It helps to separate three categories:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Input tokens:&lt;/strong&gt; the instructions, conversation and context sent to the model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thinking tokens:&lt;/strong&gt; tokens counted for the model's internal reasoning.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Output tokens:&lt;/strong&gt; the response the user sees.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All three can affect usage, latency and billing, depending on the provider and model.&lt;/p&gt;

&lt;p&gt;A setting like &lt;code&gt;thinkingBudget&lt;/code&gt; tries to influence how much reasoning the model does. But its exact meaning is model specific. Some models allow thinking to be switched off. Others require a minimum effort, treat a budget as a target rather than a hard limit, or use a different control entirely, such as &lt;code&gt;thinkingLevel&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So developers should not assume that &lt;code&gt;thinkingBudget: 0&lt;/code&gt; means zero thinking tokens, or that any budget is a guaranteed ceiling unless the model's docs explicitly promise it.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The Experiment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Model:&lt;/strong&gt; &lt;code&gt;gemini-4-hydrogen&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Interface:&lt;/strong&gt; Gemini Developer API, REST (&lt;code&gt;v1beta&lt;/code&gt;, &lt;code&gt;generateContent&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Environment:&lt;/strong&gt; a fresh free tier project, November 17, 2026&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conditions:&lt;/strong&gt; no thinking config, and &lt;code&gt;thinkingBudget&lt;/code&gt; of 0, 1024 and 8192&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Runs:&lt;/strong&gt; planned 3 per condition. The free tier's limit of 20 requests per day cut some conditions short, so they have 1 or 2 runs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Would the API accept requests containing &lt;code&gt;thinkingBudget&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;How many thinking tokens would each response report?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key measurement was the usage metadata field:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"usageMetadata"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"thoughtsTokenCount"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1466&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(This shows the field to inspect, not a complete response.) Every run also recorded the HTTP status, finish reason, prompt, output and total token counts, and latency.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. What the Numbers Showed
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foerpeq36ec9fyazbu8qc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Foerpeq36ec9fyazbu8qc.png" alt="Infographic titled Gemini thinkingBudget: Docs vs. Real Behaviour. Panels show the documentation gap, the test setup, a bar chart of thinking tokens by configuration (about 2,300 with no config, 1,320 at budget 0, 1,860 at 1024 and 2,200 at 8192), and three validation layers: request, behavior and operational." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Configuration&lt;/th&gt;
&lt;th&gt;Successful runs&lt;/th&gt;
&lt;th&gt;Thinking tokens&lt;/th&gt;
&lt;th&gt;Median latency&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No thinking config&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;2,253 to 3,139&lt;/td&gt;
&lt;td&gt;13.2 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;thinkingBudget: 0&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;1,290 to 1,466&lt;/td&gt;
&lt;td&gt;9.9 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;thinkingBudget: 1024&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;1,792 and 1,924&lt;/td&gt;
&lt;td&gt;11.0 s&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;thinkingBudget: 8192&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2,204&lt;/td&gt;
&lt;td&gt;13.7 s&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every request that got past the free tier quota returned HTTP 200. None returned a 400.&lt;/p&gt;

&lt;p&gt;Three things stand out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;First, budget zero did not switch thinking off.&lt;/strong&gt; Every run with &lt;code&gt;thinkingBudget: 0&lt;/code&gt; reported more than 1,200 thinking tokens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Second, 1024 was not a hard ceiling.&lt;/strong&gt; Both successful runs went well past 1,024.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Third, the parameter clearly did something.&lt;/strong&gt; Budget 0 used roughly half the thinking tokens of no config and had the lowest median latency. So the field was not simply ignored. It was interpreted as a nudge, not a literal limit.&lt;/p&gt;

&lt;p&gt;The sample is far too small for statistical claims, and token use depends on the prompt and run conditions. This is an interesting observation, not a universal statement about how Gemini works inside.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Why HTTP 200 Isn't Enough
&lt;/h2&gt;

&lt;p&gt;An HTTP 200 tells us the request was processed at the API level. It does not prove that every optional parameter produced the behavior the developer expected.&lt;/p&gt;

&lt;p&gt;Picture a team that changes a model setting to cut latency. The deploy succeeds, the API returns 200s, functional tests pass. But nobody measures reasoning tokens or response time. The team believes it shipped an optimization without knowing whether it did.&lt;/p&gt;

&lt;p&gt;A stronger approach checks three layers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm9rgfndz1lp0suh96gyc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm9rgfndz1lp0suh96gyc.png" alt="Infographic: Docs say 400. REST says 200. Gemini thinkingBudget key takeaway" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Request validation:&lt;/strong&gt; did the API accept the configuration?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Behavior validation:&lt;/strong&gt; did the model behave the way the configuration is documented to behave?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Operational validation:&lt;/strong&gt; did the metrics that matter actually improve, such as latency, tokens, quality and cost?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All three matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Why Model Migration Makes This Urgent
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm63h1wpkdwpz4v4eic4z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm63h1wpkdwpz4v4eic4z.png" alt="Timeline: gemini-2.5 models migrating to 3.x around December 1; thinkingBudget discouraged in favour of thinkingLevel" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Model migrations add another layer. A setting supported by one model may be deprecated, ignored, interpreted differently or rejected by its replacement.&lt;/p&gt;

&lt;p&gt;This is not hypothetical right now. Firebase's release notes say that for the Gemini Developer API, starting December 1, 2026, requests to &lt;code&gt;gemini-2.5-pro&lt;/code&gt; and &lt;code&gt;gemini-2.5-flash&lt;/code&gt; will automatically route to &lt;code&gt;gemini-3.8-flash&lt;/code&gt; and &lt;code&gt;gemini-3.5-flash-lite&lt;/code&gt;, "which do not support disabling thinking via thinkingBudget: 0". The same notes say all general-use Gemini 3.x models ignore &lt;code&gt;temperature&lt;/code&gt;, &lt;code&gt;topK&lt;/code&gt; and &lt;code&gt;topP&lt;/code&gt;, and that thinking budgets are "strongly discouraged" in favor of &lt;code&gt;thinkingLevel&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So an app that sends &lt;code&gt;thinkingBudget: 0&lt;/code&gt; today to save latency or cost may quietly behave differently after December 1, with no error to warn anyone.&lt;/p&gt;

&lt;p&gt;Treat a model migration as a behavioral compatibility change, not an endpoint swap. Before switching, record a baseline for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thinking and output token usage&lt;/li&gt;
&lt;li&gt;End-to-end latency&lt;/li&gt;
&lt;li&gt;Answer quality and task completion&lt;/li&gt;
&lt;li&gt;API errors and unsupported parameters&lt;/li&gt;
&lt;li&gt;Cost per successful request&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then run the same evaluation against the replacement model. A migration succeeds only when both functionality and operational behavior still meet your requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. How I Would Make This Reproducible
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz3g8i52u6ooul4g0ol5v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz3g8i52u6ooul4g0ol5v.png" alt="Checklist: fixed prompt, several runs per setting, log thoughtsTokenCount, compare against a no-config baseline" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The natural next step is a small open-source test utility. Given a model, a prompt set and a list of thinking configurations, it would:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Send repeated requests through the chosen API.&lt;/li&gt;
&lt;li&gt;Record the HTTP status and response metadata.&lt;/li&gt;
&lt;li&gt;Extract thinking token counts.&lt;/li&gt;
&lt;li&gt;Measure end-to-end latency.&lt;/li&gt;
&lt;li&gt;Save results as CSV or JSON.&lt;/li&gt;
&lt;li&gt;Generate comparison charts.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A simple result schema:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csvs"&gt;&lt;code&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;api_version&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;run_number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;http_status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;thought_tokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;output_tokens&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;latency_ms&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timestamp&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For a reliable comparison I would run 20 to 30 requests per condition on a paid tier, use the same prompt set, and report distributions rather than single numbers. That would answer what this small test cannot:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is the behavior consistent across runs?&lt;/li&gt;
&lt;li&gt;Does it depend on prompt complexity?&lt;/li&gt;
&lt;li&gt;Is the budget ignored, or just interpreted differently?&lt;/li&gt;
&lt;li&gt;Does fewer thinking tokens reliably mean lower latency?&lt;/li&gt;
&lt;li&gt;Does answer quality drop?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8. What Android Developers Should Check
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F26fuoco7fqhfc8cissl0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F26fuoco7fqhfc8cissl0.png" alt="Android checklist before you migrate: API path, log thought tokens, switch to thinkingLevel, re-check latency and cost" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This experiment did not test the Firebase Android SDK, and that matters. The SDK may validate settings differently, expose different options, or reject parameters before a request ever reaches the model.&lt;/p&gt;

&lt;p&gt;A practical Android check should cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SDK compatibility:&lt;/strong&gt; does your installed SDK version accept the thinking configuration you set?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Request behavior:&lt;/strong&gt; is the parameter accepted, rejected or transformed on the way out?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage telemetry:&lt;/strong&gt; can your app or backend capture thinking token counts?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency:&lt;/strong&gt; does changing the thinking setting change response time in a way users notice?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Quality:&lt;/strong&gt; do answers get less reliable with less reasoning?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For production apps, avoid logging raw user prompts or responses. Prefer aggregated metrics, sanitized diagnostics and controlled experiments.&lt;/p&gt;

&lt;p&gt;And if the target model recommends &lt;code&gt;thinkingLevel&lt;/code&gt; instead of &lt;code&gt;thinkingBudget&lt;/code&gt;, test the new setting explicitly. Don't assume it is a one to one replacement.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. The Bigger Lesson
&lt;/h2&gt;

&lt;p&gt;The takeaway is not that Gemini is broken. The evidence is too thin for that.&lt;/p&gt;

&lt;p&gt;The takeaway is that configuration correctness and behavioral correctness are different things. A model can return a perfectly successful response while behaving differently from what you expected.&lt;/p&gt;

&lt;p&gt;That is why production AI systems need more than successful API calls and functional tests. They need observability, repeatable evaluations, and regression checks whenever models, SDKs or inference settings change.&lt;/p&gt;

&lt;p&gt;Next time you configure a model to use fewer reasoning tokens, don't stop at checking that the request succeeded. Measure what actually happens.&lt;/p&gt;

&lt;p&gt;In production AI engineering, the gap between what we configure and what we observe is the gap between an assumed optimization and a verified one.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Experiment note: The numbers come from a small REST test on the Gemini Developer API run on November 17, 2026, on a free tier project, with 1 to 3 successful runs per condition. Some planned runs hit the free tier daily quota. The Firebase Android SDK path was not tested.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Have you seen gaps between documented thinking settings and actual token usage in Gemini, Claude or OpenAI models? I'd like to compare results.&lt;/p&gt;

</description>
      <category>gemini</category>
      <category>android</category>
      <category>firebase</category>
      <category>llm</category>
    </item>
    <item>
      <title>Claude Code Can Write the Feature. Can Your Team Maintain It?</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Mon, 16 Nov 2026 19:40:17 +0000</pubDate>
      <link>https://dev.to/prikshit/claude-code-can-write-the-feature-can-your-team-maintain-it-384k</link>
      <guid>https://dev.to/prikshit/claude-code-can-write-the-feature-can-your-team-maintain-it-384k</guid>
      <description>&lt;p&gt;&lt;em&gt;A practical way to judge AI-written code beyond a green build.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An AI coding agent can give you a working feature and a maintenance problem in the same commit. Both can pass the build.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine asking Claude Code to add bookmarks to an Android app. Users should be able to save an item, remove it, and find it again after closing the app.&lt;/p&gt;

&lt;p&gt;The agent produces a screen, a ViewModel, a repository, and some tests. The app opens, the save button works, and the tests turn green.&lt;/p&gt;

&lt;p&gt;Looks done.&lt;/p&gt;

&lt;p&gt;Then you notice the app already had a repository for that data. The agent has created another one, with slightly different rules.&lt;/p&gt;

&lt;p&gt;Or you close the app, reopen it, and discover that your bookmarks have vanished.&lt;/p&gt;

&lt;p&gt;These are imagined examples, but they expose the question I care about as a mobile engineer: can an AI agent add a feature without making the next feature harder to build?&lt;/p&gt;

&lt;p&gt;Generating code is only part of that job.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftezd35ud6p83b1pltzr6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftezd35ud6p83b1pltzr6.png" alt="A hand places a teal puzzle-piece module into a dashed slot on a software blueprint. A magnifying glass highlights a module with gears, and other blocks show layers, a database, a cloud and a cube. A small sequence in the corner goes from a cube to stacked layers to a puzzle piece." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Give the agent a map before asking it to build
&lt;/h2&gt;

&lt;p&gt;A feature request describes what should change. It rarely explains everything that should stay consistent.&lt;/p&gt;

&lt;p&gt;“Add bookmarks” doesn’t tell the agent which existing component owns saved data. It doesn’t explain where business rules belong or how the team handles errors.&lt;/p&gt;

&lt;p&gt;Those details live in the codebase, team decisions, and sometimes one developer’s head.&lt;/p&gt;

&lt;p&gt;A new engineer would need time to learn them. An agent needs access to them too.&lt;/p&gt;

&lt;p&gt;Before making changes, I’d ask it to find the closest existing feature and explain how it works. Where is data stored? How does a change reach the screen? Which parts can be reused?&lt;/p&gt;

&lt;p&gt;That small step gives me something useful to review before a large diff appears.&lt;/p&gt;

&lt;p&gt;I’d also keep a short set of project rules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check existing components before creating new ones.&lt;/li&gt;
&lt;li&gt;Keep business logic out of the UI.&lt;/li&gt;
&lt;li&gt;Follow the project’s current state and error-handling patterns.&lt;/li&gt;
&lt;li&gt;Explain any new dependency or change to module boundaries.&lt;/li&gt;
&lt;li&gt;Leave unrelated code alone.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The aim isn’t to write a rule for every possible mistake. It’s to make the important decisions visible.&lt;/p&gt;

&lt;p&gt;A reusable Claude Code skill (a saved set of instructions the agent loads when needed) can package that process so it doesn’t have to be explained from scratch for each feature. But the value is in the questions it makes the agent answer, not the length of the instructions.&lt;/p&gt;

&lt;p&gt;A hundred lines of vague advice won’t beat five clear rules tied to the actual app.&lt;/p&gt;

&lt;p&gt;And written rules still need checks. An instruction to reuse existing code doesn’t prove that reuse happened.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv0we3jns2l9fcp43sxey.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv0we3jns2l9fcp43sxey.png" alt="Three smartphones in a row. The left phone shows a bookmarks list of landscape photos beside a card with three green ticks. The middle phone is a dark screen circled by a teal restart arrow. The right phone shows an empty tray icon with a warning triangle." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Passing tests can protect the wrong behaviour
&lt;/h2&gt;

&lt;p&gt;Here’s the failure that worries me most.&lt;/p&gt;

&lt;p&gt;An agent decides to store bookmarks in an in-memory list instead of Room or DataStore. It then writes tests that add an item to that collection and check that the item appears.&lt;/p&gt;

&lt;p&gt;The tests pass because the collection works.&lt;/p&gt;

&lt;p&gt;But the user wanted bookmarks that survive an app restart. The tests never asked about that.&lt;/p&gt;

&lt;p&gt;The code and the tests agree. They’re both wrong about the requirement.&lt;/p&gt;

&lt;p&gt;This can happen without AI too. A developer gets attached to an implementation, then tests the choices they made instead of the outcome the user needs.&lt;/p&gt;

&lt;p&gt;The way out is to define important behaviour before writing the feature.&lt;/p&gt;

&lt;p&gt;For bookmarks, I’d start here:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Save an item. Terminate the app. Launch it again. The saved item must still appear.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then I’d check removal:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remove a saved item. Relaunch the app. The item must remain removed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;These checks are plain enough for a product manager to understand. They also make it harder to mistake a working in-memory list for durable storage.&lt;/p&gt;

&lt;p&gt;Different tests answer different questions. A ViewModel test can check what state reaches the UI; it doesn’t, by itself, prove that the real database saves data correctly.&lt;/p&gt;

&lt;p&gt;The evidence has to match the claim.&lt;/p&gt;

&lt;p&gt;A separate reviewer may catch a missing scenario, whether that reviewer is a person or another agent. But adding agents doesn’t automatically solve the problem.&lt;/p&gt;

&lt;p&gt;If every reviewer starts with the same wrong assumption, they may all approve the same mistake.&lt;/p&gt;

&lt;p&gt;Give the reviewer the original requirement and ask what evidence is missing. Agreement alone isn’t evidence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhgsbsibuejw1c4baw23v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhgsbsibuejw1c4baw23v.png" alt="A stopwatch sits at the centre, surrounded by a code file, a document under a magnifying glass, interlocking puzzle pieces with a wrench, and a phone showing a bookmarks list with a green check." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Measure the work until it’s ready to merge
&lt;/h2&gt;

&lt;p&gt;A feature generated in five minutes sounds impressive. It sounds less impressive if someone spends two hours removing duplicate code and repairing the tests.&lt;/p&gt;

&lt;p&gt;Both periods belong on the clock.&lt;/p&gt;

&lt;p&gt;That’s why I want to compare two workflows using the same small Android feature.&lt;/p&gt;

&lt;p&gt;In one, the agent gets the repository and a normal feature request. In the other, it also gets project guidance, a reusable implementation process, and explicit review checkpoints.&lt;/p&gt;

&lt;p&gt;Both should start from the same commit, use the same model and requirements, and have the same time limit. I’d repeat the runs and keep the failures in the results.&lt;/p&gt;

&lt;p&gt;This is an experiment I want to run, not a benchmark I’ve completed.&lt;/p&gt;

&lt;p&gt;I’d judge each run by five things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Required behaviour:&lt;/strong&gt; Does the feature do what the user asked?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Architecture:&lt;/strong&gt; Does it fit the app’s existing structure?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Human corrections:&lt;/strong&gt; How much repair work remains?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Total time:&lt;/strong&gt; How long until the feature is reviewed and verified?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost:&lt;/strong&gt; What did the model and tools cost to reach that point?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The structured approach might produce fewer mistakes. It might also add work without enough benefit.&lt;/p&gt;

&lt;p&gt;Either result is worth knowing.&lt;/p&gt;

&lt;p&gt;I’d be especially careful not to compare an unreviewed first draft with a fully checked implementation. They aren’t the same stage of work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F43cd7hmqswngie90irmw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F43cd7hmqswngie90irmw.png" alt="A phone showing a bookmarks list sits beside a checklist card. Saving and removing a bookmark have teal check marks, while persistence after a restart is marked with an empty amber circle. A plant, notebook and magnifying glass sit on the desk." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Try this on your next small feature
&lt;/h2&gt;

&lt;p&gt;You don’t need a fleet of agents to start. Pick one contained change and write down three observable behaviours before handing it over.&lt;/p&gt;

&lt;p&gt;Then give the agent this instruction:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before editing, inspect the closest existing feature. Explain what you will reuse, what you need to change, and how you will verify each requirement.&lt;/p&gt;

&lt;p&gt;After implementation, report which checks passed, which failed, and which behaviours remain unverified.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Read the plan. Review the diff. Check whether the report supports the claim that the feature is done.&lt;/p&gt;

&lt;p&gt;“Unit tests passed; restart behaviour wasn’t checked on a device” is a useful report. It tells you exactly where confidence ends.&lt;/p&gt;

&lt;p&gt;“Everything works” hides that boundary.&lt;/p&gt;

&lt;p&gt;What’s the most convincing-looking mistake an AI coding agent has made in your project? Drop it in the comments, especially if the tests passed.&lt;/p&gt;

&lt;p&gt;I still want AI tools to help me ship faster. But I want to count the time spent understanding, checking, and repairing what they produce.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmy5rvvybc1uj4443miv6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmy5rvvybc1uj4443miv6.png" alt="Two developers across a table hand over a modular board of connected blocks, with a documented diagram in a notebook and a phone showing a bookmarks list standing nearby." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The next developer inherits your code, not your demo.&lt;/p&gt;

</description>
      <category>android</category>
      <category>ai</category>
      <category>softwareengineering</category>
      <category>codereview</category>
    </item>
    <item>
      <title>Mobile Apps Can't Roll Back, So Agent-Written Code Needs a Release Gate</title>
      <dc:creator>Prikshit</dc:creator>
      <pubDate>Mon, 16 Nov 2026 17:38:08 +0000</pubDate>
      <link>https://dev.to/prikshit/mobile-apps-cant-roll-back-so-agent-written-code-needs-a-release-gate-4ole</link>
      <guid>https://dev.to/prikshit/mobile-apps-cant-roll-back-so-agent-written-code-needs-a-release-gate-4ole</guid>
      <description>&lt;p&gt;&lt;em&gt;Why staged rollouts are the release gate for agent-written Android and iOS code.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj0nhi6adm2bz35th0i2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj0nhi6adm2bz35th0i2z.png" alt="Flat illustration of a closed checkpoint barrier on a conveyor path. A short queue of three blank smartphones waits on the near side, a large crowd of identical phones stands beyond the gate, and a small coral warning dot hovers above it." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Every build passes one checkpoint before it reaches everyone.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When you halt a staged rollout in Google Play, no new users get that version. Everyone who already installed it keeps it.&lt;/p&gt;

&lt;p&gt;That line from the Play Console docs is the part the agentic development diagrams skip. They usually draw the loop as intent, spec, plan, code and tests, review, and finally production signals that can trigger new tasks for the agent. Most add that humans stay in charge of critical releases. What they don't show is where that human decision goes when the release is a mobile binary, and for agent-written mobile code, that's where the risk sits. The practices aren't new. What changes is how much code reaches the release branch without anyone having typed it.&lt;/p&gt;

&lt;p&gt;On a web backend, a bad deploy gets reverted, and the loop carries on. On a phone, the build is already installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The store is your deployment step, and it has no undo
&lt;/h2&gt;

&lt;p&gt;Google Play's &lt;a href="https://support.google.com/googleplay/android-developer/answer/6346149" rel="noopener noreferrer"&gt;staged rollout guide&lt;/a&gt; says it plainly. Halting stops the version from reaching more people, and users who received it "will remain on that version." Play's own tip for a bad bundle is to create and roll out a new release with a fixed one. So the only way back is forward, through another build. Re-shipping the previous code under a higher version code is the rollback mobile teams actually have, and it still waits on review and on people installing the update.&lt;/p&gt;

&lt;p&gt;Apple's &lt;a href="https://developer.apple.com/help/app-store-connect/update-your-app/release-a-version-update-in-phases" rel="noopener noreferrer"&gt;phased release&lt;/a&gt; has the same shape with a fixed schedule. Users with automatic updates get it over 7 days, starting at 1% on day one and moving through 2%, 5%, 10%, 20% and 50% before 100% on day seven. You can pause for up to 30 days in total. The catch is in the same doc, which says anyone can download the update manually from the App Store at any time. That 1% only limits automatic updates.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1c9a0m67sun1qvrv93x0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1c9a0m67sun1qvrv93x0.png" alt="Bar chart titled App Store phased release takes 7 days. Bars show the share of users with automatic updates who get the new version: day 1 1%, day 2 2%, day 3 5%, day 4 10%, day 5 20%, day 6 50%, day 7 100%. A dashed coral line at the top reads Manual App Store downloads are open to everyone from day 1. Subtitle notes pauses can total up to 30 days." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Apple's phased release schedule, charted from App Store Connect Help.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;So when the agentic development loop says production signals feed back into the agent, on mobile that means real people already hit the crash. The signal is useful. It just arrives after the damage, and there's no button that pulls the build back off their phones.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the gate should actually measure
&lt;/h2&gt;

&lt;p&gt;The gate belongs between "review approved" and "100% of users." Its job is to compare the new build with the previous one while the rollout is still small, which is a different job from checking that the app is healthy in general.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Crash-free sessions and users per build.&lt;/strong&gt; Crashlytics calculates &lt;a href="https://firebase.google.com/docs/crashlytics/crash-free-metrics" rel="noopener noreferrer"&gt;crash-free users and crash-free sessions&lt;/a&gt; and lets you filter them by build. If you &lt;a href="https://firebase.google.com/docs/crashlytics/integrate-with-google-play" rel="noopener noreferrer"&gt;link Firebase with Google Play&lt;/a&gt;, you can also filter crash reports by Play track. These metrics only count fatal events, so they won't show an ANR spike.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;New crash signatures.&lt;/strong&gt; Crashlytics can &lt;a href="https://firebase.google.com/docs/crashlytics/alerts" rel="noopener noreferrer"&gt;alert on new fatal issues&lt;/a&gt;, meaning crashes or ANRs it hasn't seen before, and on regressed issues you had marked closed. Regressed and trending alerts are on by default. New fatal, ANR and increasing-velocity alerts are not, so turn them on before you need them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;User-perceived ANR rate per version code.&lt;/strong&gt; The &lt;a href="https://developers.google.com/play/developer/reporting/reference/rest/v1beta1/vitals.anrrate/query" rel="noopener noreferrer"&gt;Play Developer Reporting API&lt;/a&gt; returns &lt;code&gt;userPerceivedAnrRate&lt;/code&gt; sliced by &lt;code&gt;versionCode&lt;/code&gt;, with hourly aggregation in UTC. The &lt;a href="https://developers.google.com/play/developer/reporting/reference/rest/v1beta1/vitals.crashrate" rel="noopener noreferrer"&gt;crash rate metric set&lt;/a&gt; works the same way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The user count behind each rate.&lt;/strong&gt; Both metric sets return &lt;code&gt;distinctUsers&lt;/code&gt;. At 1% rollout, a rate built on a few hundred users can swing wildly, so the gate should refuse to decide until there's enough data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fia09llku6vc0rfxss39f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fia09llku6vc0rfxss39f.png" alt="Flow diagram of a release gate for agent-written mobile code. Agent opens the PR, a human reviews, a small staged rollout starts, and the gate checks crash-free sessions, new fatal issues, ANR rate per version code and user count against the previous build. Bad signals halt automatically. Good signals expand only when a human decides. After a halt, no new users get the build and current users keep it." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The gate sits between a small staged rollout and everyone else.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Android vitals also publishes &lt;a href="https://developer.android.com/topic/performance/vitals" rel="noopener noreferrer"&gt;bad behavior thresholds&lt;/a&gt;. They're 1.09% for user-perceived crash rate and 0.47% for user-perceived ANR rate overall, with 8% for both on any single phone model, and Play judges them on a 28-day average. My opinion is that you shouldn't use these numbers as your gate. They decide store visibility, and by the time a 28-day average crosses 0.47%, the bad build has reached most of your users. Compare against your previous build instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  The halt button has an API
&lt;/h2&gt;

&lt;p&gt;Halting doesn't have to wait for someone to open Play Console. In the &lt;a href="https://developers.google.com/android-publisher/api-ref/rest/v3/edits.tracks" rel="noopener noreferrer"&gt;Play Developer API&lt;/a&gt;, a track release has a &lt;code&gt;status&lt;/code&gt; of &lt;code&gt;inProgress&lt;/code&gt;, &lt;code&gt;halted&lt;/code&gt; or &lt;code&gt;completed&lt;/code&gt;, plus a &lt;code&gt;userFraction&lt;/code&gt; for the staged percentage. The docs describe a halted release as one whose APKs "will no longer be served to users," while users who already have them are unaffected.&lt;/p&gt;

&lt;p&gt;Here's a halt check in Python. It reads the newest hour of vitals data for each version code and halts the release only when the new build looks worse than the previous one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&lt;/span&gt;

&lt;span class="no"&gt;PACKAGE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"com.example.app"&lt;/span&gt;
&lt;span class="no"&gt;NEW&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;PREV&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4210&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4200&lt;/span&gt;   &lt;span class="c1"&gt;# version codes being compared&lt;/span&gt;
&lt;span class="no"&gt;MIN_USERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;         &lt;span class="c1"&gt;# tune from your own data&lt;/span&gt;
&lt;span class="no"&gt;MAX_RATIO&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.2&lt;/span&gt;          &lt;span class="c1"&gt;# tune from your own release history&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;to_utc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# google.type.DateTime to datetime&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"month"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"day"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"hours"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="n"&gt;tzinfo&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;to_api&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# datetime to google.type.DateTime, hour aligned&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"year"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"month"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;month&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"day"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;day&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"hours"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"timeZone"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"UTC"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;latest_hour_anr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;reporting&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"""{versionCode: (userPerceivedAnrRate, distinctUsers)} for the newest hour."""&lt;/span&gt;
    &lt;span class="n"&gt;metric_set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="s2"&gt;"apps/{PACKAGE}/anrRateMetricSet"&lt;/span&gt;
    &lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reporting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;vitals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;anrrate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;metric_set&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;to_utc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"latestEndTime"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
               &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"freshnessInfo"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"freshnesses"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
               &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"aggregationPeriod"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"HOURLY"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;resp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;reporting&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;vitals&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;anrrate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;metric_set&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s2"&gt;"timelineSpec"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"aggregationPeriod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"HOURLY"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="s2"&gt;"startTime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;to_api&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hours&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                             &lt;span class="s2"&gt;"endTime"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;to_api&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"dimensions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"versionCode"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s2"&gt;"metrics"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"userPerceivedAnrRate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"distinctUsers"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;stats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;resp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"rows"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"dimensions"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"int64Value"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"metric"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"decimalValue"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"value"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
             &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"metrics"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="s2"&gt;"decimalValue"&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="n"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"userPerceivedAnrRate"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                       &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"distinctUsers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;decide&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;new_fatal_issue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# new_fatal_issue comes from your Crashlytics new fatal issue alert&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;new_fatal_issue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"halt"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;NEW&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="no"&gt;PREV&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;NEW&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;MIN_USERS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"wait"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;NEW&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;PREV&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;MAX_RATIO&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"halt"&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"continue"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;halt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;edit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PACKAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;ids&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"packageName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;PACKAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"editId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"track"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"production"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;track&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tracks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;halted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;release&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"releases"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;NEW&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"versionCodes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"inProgress"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;release&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"halted"&lt;/span&gt;   &lt;span class="c1"&gt;# userFraction stays as it was&lt;/span&gt;
            &lt;span class="n"&gt;halted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;halted&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PACKAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;editId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;False&lt;/span&gt;
    &lt;span class="n"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tracks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;track&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;ids&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;publisher&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;edits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;packageName&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;PACKAGE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;editId&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set &lt;code&gt;MAX_RATIO&lt;/code&gt; and &lt;code&gt;MIN_USERS&lt;/code&gt; from your own release history. The check reads a single hour because the API docs warn that adding up &lt;code&gt;distinctUsers&lt;/code&gt; across periods can count users more than once, and it edits the release already on the track instead of replacing the whole track. Also note that the &lt;a href="https://developers.google.com/android-publisher/edits" rel="noopener noreferrer"&gt;edits model&lt;/a&gt; discards an open edit if someone changes the app in Play Console at the same time, so keep one owner for rollout changes.&lt;/p&gt;

&lt;p&gt;The line I draw is the rollout percentage, and plenty of teams will disagree. A coding agent can open the release PR and even run this check. It shouldn't be the thing that raises &lt;code&gt;userFraction&lt;/code&gt;. A script that halts automatically is cheap insurance. A script that expands automatically puts the agent's judgment in front of every user at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap agent-written changes in remote flags
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;A halt only protects people who haven't updated yet. For everyone who already has, you need a flag.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpyddnjw6wg212uzc9a8v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpyddnjw6wg212uzc9a8v.png" alt="Flat illustration of a physical toggle switch in the off position on the left, linked by a dotted line to a smartphone on the right whose screen is split into a lit teal panel and a dimmed grey panel marked with a small coral dot." width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;A remote flag can switch off a code path on phones that already updated.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Firebase Remote Config changes app behavior without a new release, but the &lt;a href="https://firebase.google.com/docs/remote-config/android/get-started" rel="noopener noreferrer"&gt;default minimum fetch interval is 12 hours&lt;/a&gt;. A kill switch that waits for a normal fetch can take hours to reach a phone. &lt;a href="https://firebase.google.com/docs/remote-config/real-time" rel="noopener noreferrer"&gt;Real-time Remote Config&lt;/a&gt; pushes new values to the app as soon as they're published, so it's the version worth using for this.&lt;/p&gt;

&lt;p&gt;This follows the listener pattern from the Firebase Android guide. The flag lives in Compose state, so a screen that's already open switches paths as soon as the new value is activated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;android&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Log&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Composable&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getValue&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mutableStateOf&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;androidx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;runtime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setValue&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Firebase&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteconfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ConfigUpdate&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteconfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ConfigUpdateListener&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteconfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FirebaseRemoteConfigException&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteconfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteConfig&lt;/span&gt;

&lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="nc"&gt;Flags&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="no"&gt;CHECKOUT_V2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"checkout_v2_enabled"&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="n"&gt;remoteConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remoteConfig&lt;/span&gt;

    &lt;span class="c1"&gt;// Compose state, so screens that read it recompose when the flag flips.&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;checkoutV2&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="nf"&gt;mutableStateOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;

    &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// call once, for example from Application.onCreate()&lt;/span&gt;
        &lt;span class="c1"&gt;// The in-app default is OFF, so a device that never fetches keeps the old path.&lt;/span&gt;
        &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDefaultsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;mapOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CHECKOUT_V2&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fetchAndActivate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addOnCompleteListener&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addOnConfigUpdateListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;object&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ConfigUpdateListener&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;configUpdate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ConfigUpdate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CHECKOUT_V2&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;configUpdate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;updatedKeys&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;activate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;addOnCompleteListener&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

            &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;FirebaseRemoteConfigException&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="nc"&gt;Log&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;w&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Flags"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Config update error: ${error.code}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;refresh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;checkoutV2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;remoteConfig&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoolean&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;CHECKOUT_V2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;@Composable&lt;/span&gt;
&lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nc"&gt;CheckoutEntry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Flags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;checkoutV2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nc"&gt;CheckoutV2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nc"&gt;CheckoutV1&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default matters more than the listener. If the agent-written path is on by default, a device that never fetches config runs it anyway.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://firebase.google.com/docs/remote-config/rollouts/get-started" rel="noopener noreferrer"&gt;Remote Config rollouts&lt;/a&gt; add a second, smaller staged release inside the binary. You choose the parameter and the share of devices that get the new value, and Firebase keeps an equal-sized control group so Crashlytics can compare the two. Because of that control group, the enabled percentage has to be 50% or less unless you change the setup. If the enabled group crashes more, you roll the flag back for everyone or for a segment, with no store review involved.&lt;/p&gt;

&lt;p&gt;Flags have hard limits, though. They only cover code you wrapped. A crash in &lt;code&gt;Application.onCreate()&lt;/code&gt; before config is read can't be switched off remotely. Neither can a Room migration that already ran, a new permission in the manifest, or a class R8 stripped at build time. When an agent touches that kind of code, the flag gives you nothing and the staged rollout is the only gate left.&lt;/p&gt;

&lt;h2&gt;
  
  
  When the fix has to be a new build
&lt;/h2&gt;

&lt;p&gt;Then you ship forward and push people onto the fix. Play's &lt;a href="https://developer.android.com/guide/playcore/in-app-updates" rel="noopener noreferrer"&gt;in-app updates&lt;/a&gt; support an immediate flow, a full-screen flow the user has to accept before carrying on. The app reads &lt;code&gt;updatePriority()&lt;/code&gt;, which comes from the &lt;code&gt;inAppUpdatePriority&lt;/code&gt; value (0 to 5) set on the release. The &lt;a href="https://developer.android.com/guide/playcore/in-app-updates/kotlin-java" rel="noopener noreferrer"&gt;Kotlin guide&lt;/a&gt; notes that priority can only be set when you roll out a release and can't be changed later, so decide it before the fix goes out. For iOS, or for blocking builds that can't talk to your backend anymore, Firebase documents a &lt;a href="https://firebase.google.com/docs/remote-config/use-cases/minimum-version" rel="noopener noreferrer"&gt;minimum app version pattern&lt;/a&gt; with Remote Config.&lt;/p&gt;

&lt;h2&gt;
  
  
  A release gate for agent-written code
&lt;/h2&gt;

&lt;p&gt;Set it up in this order if you're starting from nothing.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Turn on the Crashlytics alerts that are off by default, at least new fatal issues and increasing velocity.&lt;/li&gt;
&lt;li&gt;Put every agent-written feature behind a Remote Config flag that defaults to off in the app, and use the real-time listener.&lt;/li&gt;
&lt;li&gt;Start Play rollouts small and Apple releases in phased mode. Never send agent-written changes straight to 100%.&lt;/li&gt;
&lt;li&gt;Run a halt check per version code against the previous build, with a minimum user count before it decides.&lt;/li&gt;
&lt;li&gt;Let automation halt. Keep expanding the rollout as a human decision.&lt;/li&gt;
&lt;li&gt;Decide the in-app update priority of a fix before you roll it out.&lt;/li&gt;
&lt;li&gt;Give the code no flag can reach the slowest rollout. That means startup code, database migrations, manifest changes and R8 keep rules.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If your pipeline already halts automatically, what metric triggers it, and has it ever fired on a false alarm?&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources and further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://support.google.com/googleplay/android-developer/answer/6346149" rel="noopener noreferrer"&gt;Release app updates with staged rollouts&lt;/a&gt; (Play Console Help)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.apple.com/help/app-store-connect/update-your-app/release-a-version-update-in-phases" rel="noopener noreferrer"&gt;Release a version update in phases&lt;/a&gt; (App Store Connect Help)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.android.com/topic/performance/vitals" rel="noopener noreferrer"&gt;Android vitals overview and bad behavior thresholds&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/play/developer/reporting/reference/rest/v1beta1/vitals.anrrate/query" rel="noopener noreferrer"&gt;Play Developer Reporting API, vitals.anrrate.query&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/play/developer/reporting/reference/rest/v1beta1/vitals.crashrate" rel="noopener noreferrer"&gt;Play Developer Reporting API, crash rate metric set&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developers.google.com/android-publisher/api-ref/rest/v3/edits.tracks" rel="noopener noreferrer"&gt;Play Developer API, edits.tracks&lt;/a&gt; and &lt;a href="https://developers.google.com/android-publisher/edits" rel="noopener noreferrer"&gt;Edits&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://firebase.google.com/docs/crashlytics/crash-free-metrics" rel="noopener noreferrer"&gt;Understand crash-free metrics&lt;/a&gt; (Crashlytics)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://firebase.google.com/docs/crashlytics/alerts" rel="noopener noreferrer"&gt;Crashlytics alerts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://firebase.google.com/docs/crashlytics/integrate-with-google-play" rel="noopener noreferrer"&gt;Link Crashlytics with Google Play&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://firebase.google.com/docs/remote-config/android/get-started" rel="noopener noreferrer"&gt;Get started with Remote Config on Android&lt;/a&gt; and &lt;a href="https://firebase.google.com/docs/remote-config/real-time" rel="noopener noreferrer"&gt;Real-time Remote Config&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href="https://firebase.google.com/docs/remote-config/rollouts/get-started" rel="noopener noreferrer"&gt;Get started with Remote Config rollouts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://firebase.google.com/docs/remote-config/use-cases/minimum-version" rel="noopener noreferrer"&gt;Enforce a minimum app version with Remote Config&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.android.com/guide/playcore/in-app-updates" rel="noopener noreferrer"&gt;In-app updates&lt;/a&gt; and &lt;a href="https://developer.android.com/guide/playcore/in-app-updates/kotlin-java" rel="noopener noreferrer"&gt;Support in-app updates (Kotlin or Java)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>android</category>
      <category>ios</category>
      <category>ai</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
