Skip to content

Commit 40167b6

Browse files
authored
Make robolectric tests run against SDK 29 by default (flutter#17996)
1 parent 2ab918c commit 40167b6

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

DEPS

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ allowed_hosts = [
138138
]
139139

140140
deps = {
141-
'src': 'https://github.com/flutter/buildroot.git' + '@' + '71c54fdf2bcb63c70217c0beb8deec73787439b4',
141+
'src': 'https://github.com/flutter/buildroot.git' + '@' + 'e32b5c320d36bdb7a21ecfc7a2f86787f63e8dd6',
142142

143143
# Fuchsia compatibility
144144
#

ci/licenses_golden/licenses_flutter

+1
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ FILE: ../../../flutter/shell/platform/android/platform_view_android.cc
782782
FILE: ../../../flutter/shell/platform/android/platform_view_android.h
783783
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.cc
784784
FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.h
785+
FILE: ../../../flutter/shell/platform/android/robolectric.properties
785786
FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.cc
786787
FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.h
787788
FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/basic_message_channel_unittests.cc

shell/platform/android/BUILD.gn

+6
Original file line numberDiff line numberDiff line change
@@ -455,23 +455,29 @@ action("robolectric_tests") {
455455
jar_path + ".md5.stamp",
456456
]
457457

458+
additional_jar_files = [ "robolectric.properties" ]
459+
458460
_jar_dependencies = [
459461
android_sdk_jar,
460462
embedding_jar_path,
461463
] + embedding_dependencies_jars
462464

463465
inputs = _jar_dependencies
464466

467+
_rebased_current_path = rebase_path(".")
465468
_rebased_jar_path = rebase_path(jar_path, root_build_dir)
466469
_rebased_depfile = rebase_path(depfile, root_build_dir)
467470
_rebased_classpath = rebase_path(_jar_dependencies, root_build_dir)
468471
_rebased_srcjars = rebase_path(_jar_dependencies, root_build_dir)
472+
_rebased_additional_files = rebase_path(additional_jar_files, root_build_dir)
469473

470474
args = [
471475
"--depfile=$_rebased_depfile",
472476
"--jar-path=$_rebased_jar_path",
473477
"--classpath=$_rebased_classpath",
478+
"--jar-source-base-dir=$_rebased_current_path",
474479
"--java-srcjars=$_rebased_srcjars",
480+
"--additional-jar-files=$_rebased_additional_files",
475481
]
476482

477483
args += rebase_path(sources, root_build_dir)

shell/platform/android/embedding_bundle/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ Once you have updated the dependencies, you can upload a new version by running
1414
`cipd create --pkg-def cipd.yaml`. For more, see the Chromium instructions on ["Updating a CIPD
1515
dependency"](https://chromium.googlesource.com/chromium/src/+/master/docs/cipd.md#Updating-a-CIPD-dependency) for how to upload a package update to CIPD.
1616

17-
Once you've uploaded the new version, also make sure to tag it with the updated
18-
timestamp and robolectric version (most likely still 3.8, unless you've migrated
19-
all the packages to 4+).
17+
On successful upload, you will receive a hash for the upload such as
18+
19+
`cipd: successfully uploaded and verified flutter/android/embedding_bundle:NZvE-rL3E66nHQZb5Vyl9-1Y_1MWEX7KURgOHqX2cYcC`
20+
21+
Let's further annotate the new upload with the current timestamp.
2022

2123
$ cipd set-tag flutter/android/embedding_bundle --version=<new_version_hash> -tag=last_updated:<timestamp>
2224

shell/platform/android/embedding_bundle/build.gradle

+8-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ configurations {
3333
embedding
3434
// Use any of these configurations for dependencies required for testing the embedding.
3535
embeddingTesting
36-
embeddingTesting_duplicated
36+
embeddingTesting_v16
3737
}
3838

3939
android {
@@ -49,9 +49,13 @@ android {
4949
embedding "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
5050

5151
// Testing
52+
// TODO(xster): remove these android-all compile time dependencies.
53+
// Use https://github.com/robolectric/robolectric/blob/master/robolectric/src/main/java/org/robolectric/plugins/LegacyDependencyResolver.java#L24
54+
// and specify them as runtime dependencies.
5255
embeddingTesting "org.robolectric:android-all:8.1.0-robolectric-4611349"
53-
// This is required by the robolectric test.
54-
embeddingTesting_duplicated "org.robolectric:android-all:4.1.2_r1-robolectric-r1"
56+
// Get robolectric shadows for SDK=16 used by PlatformPluginTest.
57+
embeddingTesting_v16 "org.robolectric:android-all:4.1.2_r1-robolectric-r1"
58+
embeddingTesting "androidx.fragment:fragment-testing:1.1.0"
5559
embeddingTesting "org.mockito:mockito-all:1.10.19"
5660
embeddingTesting ("org.robolectric:robolectric:4.3") {
5761
// org.hamcrest is added by org.mockito:mockito-all
@@ -71,7 +75,7 @@ task updateDependencies() {
7175
copy {
7276
from configurations.embedding
7377
from configurations.embeddingTesting
74-
from configurations.embeddingTesting_duplicated
78+
from configurations.embeddingTesting_v16
7579
into destinationDir
7680
}
7781
doLast {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Match the value at shell/platform/android/embedding_bundle/build.gradle.
2+
sdk=29

shell/platform/android/test/README.md

-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ integration tests in other repos.
2222

2323
## Q&A
2424

25-
### Why are we using Robolectric 3.8 when Robolectric 4+ is current?
26-
27-
Robolectric 4+ uses the AndroidX libraries, and the engine sources use the
28-
deprecated android.support ones. See
29-
[flutter/flutter#23586](https://github.com/flutter/flutter/issues/23586). If
30-
this is an issue we could use Jetifier on `flutter.jar` first and _then_ run
31-
the tests, but it would add an extra point of failure.
32-
3325
### My new test won't run. There's a "ClassNotFoundException".
3426

3527
See [Updating Embedding Dependencies](../embedding_bundle).

shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,9 @@
3737
import org.robolectric.annotation.Implementation;
3838
import org.robolectric.annotation.Implements;
3939

40-
// TODO(xster): we have 2 versions of robolectric Android shadows in
41-
// shell/platform/android/embedding_bundle/build.gradle. Remove the older
42-
// org.robolectric:android-all:4.1.2_r1-robolectric-r1 which doesn't have the right shadow
43-
// behaviors.
44-
@Config(manifest = Config.NONE, sdk = 27)
40+
@Config(manifest = Config.NONE)
4541
@RunWith(RobolectricTestRunner.class)
46-
@TargetApi(27)
42+
@TargetApi(29)
4743
public class FlutterViewTest {
4844
@Mock FlutterJNI mockFlutterJni;
4945
@Mock FlutterLoader mockFlutterLoader;

0 commit comments

Comments
 (0)