From 6f51c76f2c2d3b820b39cd69e8a4fb4f6e73d564 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Mon, 27 Apr 2020 22:52:15 -0700 Subject: [PATCH 1/7] Deduplicate robolectric dependencies --- shell/platform/android/embedding_bundle/build.gradle | 5 +---- .../platform/android/test/io/flutter/robolectric.properties | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 shell/platform/android/test/io/flutter/robolectric.properties diff --git a/shell/platform/android/embedding_bundle/build.gradle b/shell/platform/android/embedding_bundle/build.gradle index 418eac07c5d0c..45b2f5131b7d1 100644 --- a/shell/platform/android/embedding_bundle/build.gradle +++ b/shell/platform/android/embedding_bundle/build.gradle @@ -33,7 +33,6 @@ configurations { embedding // Use any of these configurations for dependencies required for testing the embedding. embeddingTesting - embeddingTesting_duplicated } android { @@ -50,8 +49,7 @@ android { // Testing 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" + 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 +69,6 @@ task updateDependencies() { copy { from configurations.embedding from configurations.embeddingTesting - from configurations.embeddingTesting_duplicated into destinationDir } doLast { diff --git a/shell/platform/android/test/io/flutter/robolectric.properties b/shell/platform/android/test/io/flutter/robolectric.properties new file mode 100644 index 0000000000000..49965ae28ec28 --- /dev/null +++ b/shell/platform/android/test/io/flutter/robolectric.properties @@ -0,0 +1,2 @@ +# Match the value at shell/platform/android/embedding_bundle/build.gradle. +sdk=28 \ No newline at end of file From 508bd0127a76282aedf9f1b2a2f9b1df063d50a5 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Mon, 4 May 2020 18:55:04 -0700 Subject: [PATCH 2/7] update cipd --- DEPS | 2 +- shell/platform/android/embedding_bundle/README.md | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/DEPS b/DEPS index 2fb47d785f0ae..bc4bb96a3c299 100644 --- a/DEPS +++ b/DEPS @@ -499,7 +499,7 @@ deps = { 'packages': [ { 'package': 'flutter/android/embedding_bundle', - 'version': 'last_updated:2020-03-13T15:42:26-0700' + 'version': 'last_updated:2020-05-04T18:53:14-0700' } ], 'condition': 'download_android_deps', diff --git a/shell/platform/android/embedding_bundle/README.md b/shell/platform/android/embedding_bundle/README.md index 043c3366e0d3f..28c538824ae22 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: From 5d1c7f4ab45f7ad7ad1245a58610632f988c6a15 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Wed, 6 May 2020 00:04:29 -0700 Subject: [PATCH 3/7] make robolectric.properties included properly --- shell/platform/android/BUILD.gn | 8 ++++++++ shell/platform/android/test/README.md | 8 -------- .../android/test/io/flutter/robolectric.properties | 2 +- testing/run_tests.py | 1 + 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 1ed68860f23b9..6d86b421c9af3 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -454,6 +454,10 @@ action("robolectric_tests") { jar_path + ".md5.stamp", ] + additional_jar_files = [ + "test/io/flutter/robolectric.properties", + ] + _jar_dependencies = [ android_sdk_jar, embedding_jar_path, @@ -461,16 +465,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/test/README.md b/shell/platform/android/test/README.md index b5e8b7a894e63..9817c846587a5 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/robolectric.properties b/shell/platform/android/test/io/flutter/robolectric.properties index 49965ae28ec28..aae6723b1cd09 100644 --- a/shell/platform/android/test/io/flutter/robolectric.properties +++ b/shell/platform/android/test/io/flutter/robolectric.properties @@ -1,2 +1,2 @@ # Match the value at shell/platform/android/embedding_bundle/build.gradle. -sdk=28 \ No newline at end of file +sdk=28 diff --git a/testing/run_tests.py b/testing/run_tests.py index b6769343f44a1..9edef08de7635 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -308,6 +308,7 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'): command = [ 'java', '-Drobolectric.offline=true', + '-Drobolectric.enabledSdks=28', '-Drobolectric.dependency.dir=' + embedding_deps_dir, '-classpath', ':'.join(classpath), '-Drobolectric.logging=stdout', From bae8061fa5c63eccb144b615154372b97410ae8f Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Thu, 7 May 2020 17:24:34 -0700 Subject: [PATCH 4/7] add v16 back :( --- DEPS | 4 ++-- shell/platform/android/BUILD.gn | 2 +- shell/platform/android/embedding_bundle/build.gradle | 4 ++++ .../android/{test/io/flutter => }/robolectric.properties | 2 +- .../test/io/flutter/embedding/android/FlutterViewTest.java | 7 +------ testing/run_tests.py | 1 - 6 files changed, 9 insertions(+), 11 deletions(-) rename shell/platform/android/{test/io/flutter => }/robolectric.properties (91%) diff --git a/DEPS b/DEPS index bc4bb96a3c299..92162422257ab 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 # @@ -499,7 +499,7 @@ deps = { 'packages': [ { 'package': 'flutter/android/embedding_bundle', - 'version': 'last_updated:2020-05-04T18:53:14-0700' + 'version': 'last_updated:2020-03-13T15:42:26-0700' } ], 'condition': 'download_android_deps', diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 6d86b421c9af3..19ef058b063ad 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -455,7 +455,7 @@ action("robolectric_tests") { ] additional_jar_files = [ - "test/io/flutter/robolectric.properties", + "robolectric.properties", ] _jar_dependencies = [ diff --git a/shell/platform/android/embedding_bundle/build.gradle b/shell/platform/android/embedding_bundle/build.gradle index 45b2f5131b7d1..2be9a6658fcb0 100644 --- a/shell/platform/android/embedding_bundle/build.gradle +++ b/shell/platform/android/embedding_bundle/build.gradle @@ -33,6 +33,7 @@ configurations { embedding // Use any of these configurations for dependencies required for testing the embedding. embeddingTesting + embeddingTesting_v16 } android { @@ -49,6 +50,8 @@ android { // Testing embeddingTesting "org.robolectric:android-all:8.1.0-robolectric-4611349" + // 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") { @@ -69,6 +72,7 @@ task updateDependencies() { copy { from configurations.embedding from configurations.embeddingTesting + from configurations.embeddingTesting_v16 into destinationDir } doLast { diff --git a/shell/platform/android/test/io/flutter/robolectric.properties b/shell/platform/android/robolectric.properties similarity index 91% rename from shell/platform/android/test/io/flutter/robolectric.properties rename to shell/platform/android/robolectric.properties index aae6723b1cd09..7378b4e6a2ca7 100644 --- a/shell/platform/android/test/io/flutter/robolectric.properties +++ b/shell/platform/android/robolectric.properties @@ -1,2 +1,2 @@ # Match the value at shell/platform/android/embedding_bundle/build.gradle. -sdk=28 +sdk=29 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 954ed42e32178..9a0ad4eee078c 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,8 @@ 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) public class FlutterViewTest { @Mock FlutterJNI mockFlutterJni; @Mock FlutterLoader mockFlutterLoader; diff --git a/testing/run_tests.py b/testing/run_tests.py index 9edef08de7635..b6769343f44a1 100755 --- a/testing/run_tests.py +++ b/testing/run_tests.py @@ -308,7 +308,6 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'): command = [ 'java', '-Drobolectric.offline=true', - '-Drobolectric.enabledSdks=28', '-Drobolectric.dependency.dir=' + embedding_deps_dir, '-classpath', ':'.join(classpath), '-Drobolectric.logging=stdout', From c623e56fbde29c17e9939e20ce572eb5f88cd58e Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Thu, 7 May 2020 18:24:05 -0700 Subject: [PATCH 5/7] removed one annotation too many --- shell/platform/android/embedding_bundle/build.gradle | 3 +++ .../test/io/flutter/embedding/android/FlutterViewTest.java | 1 + 2 files changed, 4 insertions(+) diff --git a/shell/platform/android/embedding_bundle/build.gradle b/shell/platform/android/embedding_bundle/build.gradle index 2be9a6658fcb0..a76082267c3a7 100644 --- a/shell/platform/android/embedding_bundle/build.gradle +++ b/shell/platform/android/embedding_bundle/build.gradle @@ -49,6 +49,9 @@ 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" // Get robolectric shadows for SDK=16 used by PlatformPluginTest. embeddingTesting_v16 "org.robolectric:android-all:4.1.2_r1-robolectric-r1" 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 9a0ad4eee078c..08dae7ed8b0fc 100644 --- a/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java +++ b/shell/platform/android/test/io/flutter/embedding/android/FlutterViewTest.java @@ -39,6 +39,7 @@ @Config(manifest = Config.NONE) @RunWith(RobolectricTestRunner.class) +@TargetApi(29) public class FlutterViewTest { @Mock FlutterJNI mockFlutterJni; @Mock FlutterLoader mockFlutterLoader; From 4de73af2d3e729c4cecc78f0ca86587fdb3e022c Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Thu, 7 May 2020 21:54:55 -0700 Subject: [PATCH 6/7] autoformat gn --- shell/platform/android/BUILD.gn | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shell/platform/android/BUILD.gn b/shell/platform/android/BUILD.gn index 19ef058b063ad..d6f1f245a1e77 100644 --- a/shell/platform/android/BUILD.gn +++ b/shell/platform/android/BUILD.gn @@ -454,9 +454,7 @@ action("robolectric_tests") { jar_path + ".md5.stamp", ] - additional_jar_files = [ - "robolectric.properties", - ] + additional_jar_files = [ "robolectric.properties" ] _jar_dependencies = [ android_sdk_jar, From ce67f3bfa08b64f1d811c2868190724d86c5f4af Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Thu, 7 May 2020 22:06:29 -0700 Subject: [PATCH 7/7] update license --- ci/licenses_golden/licenses_flutter | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 6b618b6f07381..0f9e00cd829ea 100644 --- 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