Fixes https://github.com/flutter/flutter/issues/163561 Fixes https://github.com/flutter/flutter/issues/156488 Fixes https://github.com/flutter/flutter/issues/156489 Fixes https://github.com/flutter/flutter/issues/163520 Forked from https://github.com/flutter/flutter/pull/163692 Only release background image readers on Android 14. I believe reader disposal is the ultimate cause of https://github.com/flutter/flutter/issues/162147 , where older android devices don't seem to handle backgrounding the same way we expect on newer devices. The result of this is a crash in HWUI, which is unexpected. Since we only ever did the background release to work around an ANdroid 14 bug, and because it breaks other functionality like background playback - we should remove it for all targets besides 14.
Unit testing Java code
All Java code in the engine should now be able to be tested with Robolectric 4.12.1 and JUnit 4. The test suite has been added after the bulk of the Java code was first written, so most of these classes do not have existing tests. Ideally code after this point should be tested, either with unit tests here or with integration tests in other repos.
Adding a new test
- Create a file under
test/matching the path and name of the class under test. For example,shell/platform/android/io/flutter/util/Preconditions.java->shell/platform/android/**test**/io/flutter/util/Preconditions**Test**.java. - Add your file to the
sourcesof therobolectric_testsbuild target in/shell/platform/android/BUILD.gn. This compiles the test class into the test jar. - Import your test class and add it to the
@SuiteClassesannotation inFlutterTestSuite.java. This makes sure the test is actually executed at run time. - Write your test.
- Build and run with
testing/run_tests.py [--type=java] [--java-filter=<test_class_name>].
Example: from engine/src/flutter on a Mac
et build -c android_debug_unopt_arm64
testing/run_tests.py --android-variant=android_debug_unopt_arm64 --type=java --java-filter=io.flutter.embedding.android.FlutterViewTest
Note that testing/run_tests.py does not build the engine binaries; instead they
should be built prior to running this command and also when the source files
change. See Compiling the engine
for details on how to do so.
Q&A
My new test won't run. There's a "ClassNotFoundException".
See Updating Embedding Dependencies.
My new test won't compile. It can't find one of my imports.
See Updating Embedding Dependencies.
My test does not show log output in the console
Import org.robolectric.shadows.ShadowLog; then
Use ShadowLog.stream = System.out; in your test or setup method.