If you write Java JUnit tests (such as Robolectric tests) against the Flutter engine's Java embedding and used the `FlutterMain.setIsRunningInRobolectricTest(true)` API, replace it with the following:
Original behavior
The `FlutterMain` class itself is being deprecated and replaced with the `FlutterInjector` class. The `FlutterMain` class uses a number of static variables and functions than make it difficult to test. `FlutterMain.setIsRunningInRobolectricTest()` is one ad-hoc static mechanism to allow tests to run on the host machine on JVM without loading the `libflutter.so` native library (which can't be done on the host machine).
New behavior
This engine commit removed the `FlutterMain.setIsRunningInRobolectricTest()` testing function; and the following commit added a `FlutterInjector` class to assist testing. PR 20473 further refactored `FlutterLoader` and `FlutterJNI` to allow for additional mocking and testing.
- Who is affected
- Any code still referencing the removed API will fail to compile after upgrading. Code that uses FlutterMain, FlutterInjector, FlutterLoader and related APIs.
- Practical impact
- Compile errors until migrated; must be addressed before upgrading.
- What action should I take?
- Follow the official migration guide below, update affected call sites, run `dart fix --apply` where a fix is available, then run your tests.
Before and after (from the official guide)
| 1 | − | FlutterMain.setIsRunningInRobolectricTest(true); |
| 1 | + | FlutterJNI mockFlutterJNI = mock(FlutterJNI.class); |
| 2 | + | FlutterInjector.setInstance( |
| 3 | + | new FlutterInjector.Builder() |
| 4 | + | .setFlutterLoader(new FlutterLoader(mockFlutterJNI)) |
| 5 | + | .build()); |
Raw before / after
FlutterMain.setIsRunningInRobolectricTest(true);
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
FlutterInjector.setInstance(
new FlutterInjector.Builder()
.setFlutterLoader(new FlutterLoader(mockFlutterJNI))
.build());Official migration guide (excerpt, © The Flutter Authors, CC BY 3.0)
Code before migration:
FlutterMain.setIsRunningInRobolectricTest(true);Code after migration:
FlutterJNI mockFlutterJNI = mock(FlutterJNI.class);
FlutterInjector.setInstance(
new FlutterInjector.Builder()
.setFlutterLoader(new FlutterLoader(mockFlutterJNI))
.build());AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.Listed in the official breaking-changes index; title states removal.
An official announcement or migration guide documents an intended behaviour or API change. A verified source change (git diff) shows code changed but does not by itself prove a public API is breaking. AI interpretations are labelled and never used to classify a change.
- Source commit
- b3045439b7c0
- Source last updated
- Oct 21, 2026
- Last synchronized
- Oct 21, 2026
- Publication status
- published
Publication history
- Oct 21, 2026, 8:31 PM: new → published (ingestion) — Backed by an official breaking-change/migration guide.
AI_PROVIDER (for example to openai-compatible with a local Ollama or LM Studio endpoint) to enable grounded explanations. Everything else on this page works without an AI provider.