-
Notifications
You must be signed in to change notification settings - Fork 3.4k
add breaking change for FlutterMain.setIsRunningInRobolectricTest removal #4561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/docs/release/breaking-changes/android-setIsRunningInRobolectricTest-removed.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| --- | ||
| title: FlutterMain.setIsRunningInRobolectricTest on Android removed | ||
| description: The test-only FlutterMain.setIsRunningInRobolectricTest API on the Android engine is consolidated into the FlutterInjector. | ||
| --- | ||
|
|
||
| ## Summary | ||
|
|
||
| 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 | ||
|
|
||
| ```java | ||
| FlutterJNI mockFlutterJNI = mock(FlutterJNI.class); | ||
| FlutterInjector.setInstance( | ||
| new FlutterInjector.Builder() | ||
| .setFlutterLoader(new FlutterLoader(mockFlutterJNI)) | ||
| .build()); | ||
| ``` | ||
|
|
||
| This should be very uncommon. | ||
|
|
||
| ## Context | ||
|
|
||
| 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). | ||
|
|
||
| Rather than one-off solutions, all dependency injections needed for tests | ||
| in Flutter's Android/Java engine embedding are now moved to the | ||
| [`FlutterInjector`](https://cs.opensource.google/flutter/engine/+/master:shell/platform/android/io/flutter/FlutterInjector.java) | ||
| class. | ||
|
|
||
| Within the `FlutterInjector` class, the `setFlutterLoader()` Builder | ||
| function allows for control of how the [`FlutterLoader`](https://cs.opensource.google/flutter/engine/+/master:shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java) | ||
| class locates and loads the libflutter.so library. | ||
|
|
||
| ## Description of change | ||
|
|
||
| https://github.com/flutter/engine/commit/15f5696c4139a21e1fc54014ce17d01f6ad1737c#diff-599e1d64442183ead768757cca6805c3L154 | ||
| removes the `FlutterMain.setIsRunningInRobolectricTest()` testing function. | ||
|
|
||
| https://github.com/flutter/engine/commit/15f5696c4139a21e1fc54014ce17d01f6ad1737c#diff-f928557f2d60773a8435366400fa42ed | ||
| adds a `FlutterInjector` class to assist testing. | ||
|
|
||
| https://github.com/flutter/engine/pull/20473 further refactors FlutterLoader and FlutterJNI | ||
| to allow for additional mocking/testing. | ||
|
|
||
| ## Migration guide | ||
|
|
||
| Code before migration: | ||
|
|
||
| ```java | ||
| FlutterMain.setIsRunningInRobolectricTest(true); | ||
| ``` | ||
|
|
||
| Code after migration: | ||
|
|
||
| ```java | ||
| FlutterJNI mockFlutterJNI = mock(FlutterJNI.class); | ||
| FlutterInjector.setInstance( | ||
| new FlutterInjector.Builder() | ||
| .setFlutterLoader(new FlutterLoader(mockFlutterJNI)) | ||
| .build()); | ||
| ``` | ||
|
|
||
| ## Timeline | ||
|
|
||
| Landed in version: 1.22.0-2.0.pre.133<br> | ||
| In stable release: not yet | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.