From 40167b68ed4a0070726e692d7ddbc762cf3b4e2c Mon Sep 17 00:00:00 2001 From: xster Date: Thu, 7 May 2020 23:29:02 -0700 Subject: [PATCH] Make robolectric tests run against SDK 29 by default (#17996) --- DEPS | 2 +- ci/licenses_golden/licenses_flutter | 1 + shell/platform/android/BUILD.gn | 6 ++++++ shell/platform/android/embedding_bundle/README.md | 8 +++++--- shell/platform/android/embedding_bundle/build.gradle | 12 ++++++++---- shell/platform/android/robolectric.properties | 2 ++ shell/platform/android/test/README.md | 8 -------- .../flutter/embedding/android/FlutterViewTest.java | 8 ++------ 8 files changed, 25 insertions(+), 22 deletions(-) create mode 100644 shell/platform/android/robolectric.properties diff --git a/DEPS b/DEPS index 90bfe0b85..d88fdddcf 100644 --- a/DEPS +++ b/DEPS @@ -138,7 +138,7 @@ allowed_hosts = [ ] deps = { - 'src': 'https://github.com/flutter/buildroot.git' + '@' + '71c54fdf2bcb63c70217c0beb8deec73787439b4', + 'src': 'https://github.com/flutter/buildroot.git' + '@' + 'e32b5c320d36bdb7a21ecfc7a2f86787f63e8dd6', # Fuchsia compatibility # diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index e42df4418..c7a07c4ac 100755 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -782,6 +782,7 @@ FILE: ../../../flutter/shell/platform/android/platform_view_android.cc FILE: ../../../flutter/shell/platform/android/platform_view_android.h FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.cc FILE: ../../../flutter/shell/platform/android/platform_view_android_jni.h +FILE: ../../../flutter/shell/platform/android/robolectric.properties FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.cc FILE: ../../../flutter/shell/platform/android/vsync_waiter_android.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/basic_message_channel_unittests.cc diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 8f5a6e364..05b176b42 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -455,6 +455,8 @@ action("robolectric_tests") { jar_path + ".md5.stamp", ] + additional_jar_files = [ "robolectric.properties" ] + _jar_dependencies = [ android_sdk_jar, embedding_jar_path, @@ -462,16 +464,20 @@ action("robolectric_tests") { inputs = _jar_dependencies + _rebased_current_path = rebase_path(".") _rebased_jar_path = rebase_path(jar_path, root_build_dir) _rebased_depfile = rebase_path(depfile, root_build_dir) _rebased_classpath = rebase_path(_jar_dependencies, root_build_dir) _rebased_srcjars = rebase_path(_jar_dependencies, root_build_dir) + _rebased_additional_files = rebase_path(additional_jar_files, root_build_dir) args = [ "--depfile=$_rebased_depfile", "--jar-path=$_rebased_jar_path", "--classpath=$_rebased_classpath", + "--jar-source-base-dir=$_rebased_current_path", "--java-srcjars=$_rebased_srcjars", + "--additional-jar-files=$_rebased_additional_files", ] args += rebase_path(sources, root_build_dir) diff --git a/shell/platform/android/embedding_bundle/README.md b/shell/platform/android/embedding_bundle/README.md index 043c3366e..28c538824 100644 --- a/shell/platform/android/embedding_bundle/README.md +++ b/shell/platform/android/embedding_bundle/README.md @@ -14,9 +14,11 @@ Once you have updated the dependencies, you can upload a new version by running `cipd create --pkg-def cipd.yaml`. For more, see the Chromium instructions on ["Updating a CIPD dependency"](https://chromium.googlesource.com/chromium/src/+/master/docs/cipd.md#Updating-a-CIPD-dependency) for how to upload a package update to CIPD. -Once you've uploaded the new version, also make sure to tag it with the updated -timestamp and robolectric version (most likely still 3.8, unless you've migrated -all the packages to 4+). +On successful upload, you will receive a hash for the upload such as + +`cipd: successfully uploaded and verified flutter/android/embedding_bundle:NZvE-rL3E66nHQZb5Vyl9-1Y_1MWEX7KURgOHqX2cYcC` + +Let's further annotate the new upload with the current timestamp. $ cipd set-tag flutter/android/embedding_bundle --version= -tag=last_updated: diff --git a/shell/platform/android/embedding_bundle/build.gradle b/shell/platform/android/embedding_bundle/build.gradle index 418eac07c..a76082267 100644 --- a/shell/platform/android/embedding_bundle/build.gradle +++ b/shell/platform/android/embedding_bundle/build.gradle @@ -33,7 +33,7 @@ configurations { embedding // Use any of these configurations for dependencies required for testing the embedding. embeddingTesting - embeddingTesting_duplicated + embeddingTesting_v16 } android { @@ -49,9 +49,13 @@ android { embedding "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" // Testing + // TODO(xster): remove these android-all compile time dependencies. + // Use https://github.com/robolectric/robolectric/blob/master/robolectric/src/main/java/org/robolectric/plugins/LegacyDependencyResolver.java#L24 + // and specify them as runtime dependencies. embeddingTesting "org.robolectric:android-all:8.1.0-robolectric-4611349" - // This is required by the robolectric test. - embeddingTesting_duplicated "org.robolectric:android-all:4.1.2_r1-robolectric-r1" + // Get robolectric shadows for SDK=16 used by PlatformPluginTest. + embeddingTesting_v16 "org.robolectric:android-all:4.1.2_r1-robolectric-r1" + embeddingTesting "androidx.fragment:fragment-testing:1.1.0" embeddingTesting "org.mockito:mockito-all:1.10.19" embeddingTesting ("org.robolectric:robolectric:4.3") { // org.hamcrest is added by org.mockito:mockito-all @@ -71,7 +75,7 @@ task updateDependencies() { copy { from configurations.embedding from configurations.embeddingTesting - from configurations.embeddingTesting_duplicated + from configurations.embeddingTesting_v16 into destinationDir } doLast { diff --git a/shell/platform/android/robolectric.properties b/shell/platform/android/robolectric.properties new file mode 100644 index 000000000..7378b4e6a --- /dev/null +++ b/shell/platform/android/robolectric.properties @@ -0,0 +1,2 @@ +# Match the value at shell/platform/android/embedding_bundle/build.gradle. +sdk=29 diff --git a/shell/platform/android/test/README.md b/shell/platform/android/test/README.md index b5e8b7a89..9817c8465 100644 --- a/shell/platform/android/test/README.md +++ b/shell/platform/android/test/README.md @@ -22,14 +22,6 @@ integration tests in other repos. ## Q&A -### Why are we using Robolectric 3.8 when Robolectric 4+ is current? - -Robolectric 4+ uses the AndroidX libraries, and the engine sources use the -deprecated android.support ones. See -[flutter/flutter#23586](https://github.com/flutter/flutter/issues/23586). If -this is an issue we could use Jetifier on `flutter.jar` first and _then_ run -the tests, but it would add an extra point of failure. - ### My new test won't run. There's a "ClassNotFoundException". See [Updating Embedding Dependencies](../embedding_bundle). diff --git a/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java b/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java index 954ed42e3..08dae7ed8 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java @@ -37,13 +37,9 @@ import org.robolectric.annotation.Config; import org.robolectric.annotation.Implementation; import org.robolectric.annotation.Implements; -// TODO(xster): we have 2 versions of robolectric Android shadows in -// shell/platform/android/embedding_bundle/build.gradle. Remove the older -// org.robolectric:android-all:4.1.2_r1-robolectric-r1 which doesn't have the right shadow -// behaviors. -@Config(manifest = Config.NONE, sdk = 27) +@Config(manifest = Config.NONE) @RunWith(RobolectricTestRunner.class) -@TargetApi(27) +@TargetApi(29) public class FlutterViewTest { @Mock FlutterJNI mockFlutterJni; @Mock FlutterLoader mockFlutterLoader; -- GitLab