diff options
author | Anton Hansson <hansson@google.com> | 2020-07-20 18:32:22 +0100 |
---|---|---|
committer | Anton Hansson <hansson@google.com> | 2020-07-21 10:51:28 +0100 |
commit | 55539aa0a95381cbba0f499a2fd58e67189e9a1a (patch) | |
tree | bf568a7210659d570c5c65749255f320d6b8014f | |
parent | 130819624dfd7771d7fb8f60ddf51574ea3a1432 (diff) | |
download | robolectric-shadows-55539aa0a95381cbba0f499a2fd58e67189e9a1a.tar.gz |
Make robolectric runner auto-inject dependency jar
Currently robolectric tests are all manually depending on
robolectric_android-all-stub, which has the unfortunate side-effect
of depending on all private platform APIs at compile time.
Make robolectric_android-all-stub an empty jar, and instead inject
the equivalent host library at runtime.
Bug: 157451444
Test: presubmit
Test: run settings tests
Change-Id: I1a4462a50e7d0533a59fb4cb02f863e122baa64c
-rw-r--r-- | Android.bp | 8 | ||||
-rw-r--r-- | run_robolectric_module_tests.mk | 2 | ||||
-rw-r--r-- | run_robotests.mk | 3 |
3 files changed, 9 insertions, 4 deletions
diff --git a/Android.bp b/Android.bp index 36b5ecf98..2e19d3d01 100644 --- a/Android.bp +++ b/Android.bp @@ -16,9 +16,14 @@ package { default_visibility: [":__subpackages__"], } +// Empty library. Should be removed java_library { name: "robolectric_android-all-stub", + visibility: ["//visibility:public"], +} +java_library { + name: "robolectric_android-all", static_libs: [ "conscrypt", "core-icu4j", @@ -51,7 +56,6 @@ java_library { ], dest: "android-all-robolectric.jar", }, - visibility: ["//visibility:public"], } // build.prop file created by module type defined in soong/robolectric.go @@ -96,7 +100,7 @@ java_genrule { // Make robolectric_android-all-stub available as a host jar java_device_for_host { name: "robolectric-host-android_all", - libs: ["robolectric_android-all-stub"], + libs: ["robolectric_android-all"], } //############################################# diff --git a/run_robolectric_module_tests.mk b/run_robolectric_module_tests.mk index 1c190e38b..4d5cb95c5 100644 --- a/run_robolectric_module_tests.mk +++ b/run_robolectric_module_tests.mk @@ -35,7 +35,7 @@ ifdef test_resources_directory endif # Define rules that copy android-all jars to the intermediates folder. -local_android_all_source_jar := $(call intermediates-dir-for, JAVA_LIBRARIES, robolectric_android-all-stub, , COMMON)/classes.jar +local_android_all_source_jar := $(call java-lib-files,robolectric-host-android_all,HOST) android_all_source_dir := prebuilts/misc/common/robolectric/android-all android_all_target_dir := $(intermediates)/android-all copy_android_all_jar_pairs := \ diff --git a/run_robotests.mk b/run_robotests.mk index 8e70760ac..6251ae1ae 100644 --- a/run_robotests.mk +++ b/run_robotests.mk @@ -105,6 +105,7 @@ ifneq ($(DISABLE_ROBO_RUN_TESTS),true) # The jars needed to run the tests. my_jars := \ $(my_robolectric_jars) \ + $(call java-lib-files,robolectric-host-android_all,HOST) \ $(call java-lib-files,junitxml) \ $(my_srcs_jars) @@ -116,7 +117,7 @@ ifneq ($(DISABLE_ROBO_RUN_TESTS),true) my_filename_stem := test # Define rules that copy android-all jars to the intermediates folder. - local_android_all_source_jar := $(call intermediates-dir-for, JAVA_LIBRARIES, robolectric_android-all-stub,,COMMON)/classes.jar + local_android_all_source_jar := $(call java-lib-files,robolectric-host-android_all,HOST) android_all_lib_path := prebuilts/misc/common/robolectric/android-all my_robolectric_path := $(intermediates.COMMON)/android-all copy_android_all_jar_pairs := \ |