Skip to content

fix(robolectric): stop shipping robolectric.properties in the library - #5

Closed
kikoso wants to merge 1 commit into
mainfrom
fix/robolectric-no-shipped-properties
Closed

kikoso wants to merge 1 commit into
mainfrom
fix/robolectric-no-shipped-properties

Conversation

@kikoso

@kikoso kikoso commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

robolectric-testing packages a top-level robolectric.properties that lists all 16 Maps shadows. Once a consumer adds the dependency, Robolectric picks that file up from the classpath and registers the Maps shadows for every Robolectric test in the project, including tests that never touch Maps. If the consumer has their own robolectric.properties (for sdk, application, and so on), only one of the two files wins, depending on classpath order.

This removes all three copies from the library sources:

  • src/main/resources/robolectric.properties: the one that ships in the AAR and causes the problem.
  • src/main/resources/com/google/maps/android/robolectric/shadows/robolectric.properties: a package-level copy that had drifted and only listed 10 of the 16 shadows.
  • src/main/java/.../shadows/robolectric.properties: never packaged, since Gradle does not copy resources from src/main/java.

@EnableMapsShadows stays the supported way to turn on the shadows, and every test in this repo already uses it (or an explicit @Config(shadows = ...)). The module's own test resources keep their robolectric.properties.

Behavior change for rc01 users: anyone relying on the shadows being picked up automatically needs to add @EnableMapsShadows to their test classes. I updated the module README, which advertised the automatic discovery.

RobolectricConfigLeakTest in golden-testing guards this. That module consumes robolectric-testing the same way an app does, so its test classpath shows what consumers get. Both tests fail on main and pass with this change.

Ran ./gradlew test lint spotlessCheck apiCheck docs:dokkaGenerate: all green.

@kikoso

kikoso commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Correction: this PR is not green. My local run was served from the Gradle build cache. With --rerun-tasks, 16 of 21 :app unit tests fail with GooglePlayServicesMissingManifestValueException, same as CI.

The cause is that @EnableMapsShadows never registers anything. It puts @Config(shadows = [...]) on an annotation class, and Robolectric does not read @Config through meta-annotations. The tests only passed because the shipped robolectric.properties registered the shadows globally.

So the annotation has to work before this file can go. Holding this PR until we decide how.

@kikoso

kikoso commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Closing this for now. The file is the only thing that registers the Maps shadows today, for us and for anyone on rc01, so removing it first breaks every consumer.

Plan instead:

  1. Add a MapsRobolectricTestRunner that registers the shadows through buildGlobalConfig(), and deprecate @EnableMapsShadows in favor of it (it can't be fixed, since Robolectric doesn't read @Config through annotations).
  2. Keep shipping robolectric.properties through the RCs, and document that an app with its own root robolectric.properties can lose it.
  3. Remove the file before 1.0.0 stable, reusing the leak test from this PR.

I'll link the runner PR here.

@kikoso

kikoso commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

Runner PR: #12. With it, all 131 tests pass with every robolectric.properties removed. The buildGlobalConfig() override I proposed above does not work (static, first runner wins), so it binds a GlobalConfigProvider through the injector instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants