Skip to content

Commit 5615abe

Browse files
committed
add breaking change for FlutterMain.setIsRunningInRobolectricTest removal
1 parent 86f6764 commit 5615abe

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: FlutterMain.setIsRunningInRobolectricTest on Android removed
3+
description: The test-only FlutterMain.setIsRunningInRobolectricTest API on
4+
the Android engine is consolidated into the FlutterInjector.
5+
---
6+
7+
## Summary
8+
9+
If you write Java JUnit tests (such as Robolectric tests) against the Flutter
10+
engine's Java embedding and used the
11+
`FlutterMain.setIsRunningInRobolectricTest(true)` API, replace it with
12+
`FlutterInjector.setInstance(new FlutterInjector.Builder().setShouldLoadNative(false).build())`.
13+
14+
This should be very uncommon.
15+
16+
## Context
17+
18+
The `FlutterMain` class itself is being deprecated and replaced with the
19+
`FlutterInjector` class. The `FlutterMain` class itself used a number of
20+
static variables and functions than make it difficult to test. The
21+
`FlutterMain.setIsRunningInRobolectricTest()` is one ad-hoc static
22+
mechanism to allow tests to run on the host machine on JVM without
23+
loading the libflutter.so native library (which can't be done on the host
24+
machine).
25+
26+
Rather than one-off solutions, all dependency injections needed for tests
27+
in Flutter's Android/Java engine embedding are now moved to the
28+
[`FlutterInjector`](https://cs.opensource.google/flutter/engine/+/master:shell/platform/android/io/flutter/FlutterInjector.java)
29+
class.
30+
31+
Within the `FlutterInjector` class, the `setShouldLoadNative()` Builder
32+
function allows for control of whether to load the native library.
33+
34+
## Description of change
35+
36+
https://github.com/flutter/engine/commit/15f5696c4139a21e1fc54014ce17d01f6ad1737c#diff-599e1d64442183ead768757cca6805c3L154
37+
removes the `FlutterMain.setIsRunningInRobolectricTest()` testing function.
38+
39+
https://github.com/flutter/engine/commit/15f5696c4139a21e1fc54014ce17d01f6ad1737c#diff-f928557f2d60773a8435366400fa42ed
40+
adds a `FlutterInjector` class to assist testing.
41+
42+
## Migration guide
43+
44+
Code before migration:
45+
46+
<!-- skip -->
47+
```java
48+
FlutterMain.setIsRunningInRobolectricTest(true);
49+
```
50+
51+
Code after migration:
52+
53+
```java
54+
FlutterInjector.setInstance(new FlutterInjector.Builder().setShouldLoadNative(false).build());
55+
```
56+
57+
## Timeline
58+
59+
Landed in version: 1.22.0-2.0.pre.133<br>
60+
In stable release: not yet

src/docs/release/breaking-changes/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ release, and listed in alphabetical order:
1616
* [Material Chip button semantics][]
1717
* [Network Policy on iOS and Android][]
1818
* [The new Form, FormField auto-validation API][]
19+
* [Android FlutterMain.setIsRunningInRobolectricTest testing API removed][]
1920

2021
[Android v1 embedding app and plugin creation deprecation]: /docs/release/breaking-changes/android-v1-embedding-create-deprecation
2122
[Material Chip button semantics]: /docs/release/breaking-changes/material-chip-button-semantics
2223
[Network Policy on iOS and Android]: /docs/release/breaking-changes/network-policy-ios-android
2324
[The new Form, FormField auto-validation API]: /docs/release/breaking-changes/form-field-autovalidation-api
25+
[Android FlutterMain.setIsRunningInRobolectricTest testing API removed]: /docs/release/breaking-change/android-setIsRunningInRobolectricTest-removed
2426

2527
### Released in Flutter 1.20
2628

0 commit comments

Comments
 (0)