Skip to content

[DO NOT MERGE] [various] Update Robolectric to 4.17 - #13041

Open
jesswrd wants to merge 4 commits into
flutter:mainfrom
jesswrd:pack-robl-to-37
Open

jesswrd wants to merge 4 commits into
flutter:mainfrom
jesswrd:pack-robl-to-37

Conversation

@jesswrd

@jesswrd jesswrd commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

DO NOT MERGE. Wait until #13031 and #13040 merge.

Updates test dependencies to Robolectric 4.17.

Partially Addresses flutter/flutter#193404

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2

…n unit tests

JDK 17+ enforces strong encapsulation of JDK internals, so Robolectric
requires a set of --add-opens flags on the unit test JVM
(https://robolectric.org/getting-started/#running-with-java-17-and-higher).

The current Robolectric 4.16 does not need them for these tests, but
starting with Robolectric 4.17 the per-test environment setup
(AndroidTestEnvironment.setUpApplicationState ->
ApplicationSharedMemory.create -> FileDescriptorInterceptor) reflects
into jdk.internal.access.SharedSecrets and fails with:

  IllegalAccessException: ... module java.base does not export
  jdk.internal.access to unnamed module

Add the flag set recommended by Robolectric to the existing
testOptions.unitTests.all block of every plugin that uses Robolectric,
ahead of the 4.17 bump. These args only affect each plugin's own unit
test JVM; they are not part of the published plugin.

Plugins: camera_android, camera_android_camerax, file_selector_android,
google_maps_flutter_android, image_picker_android,
in_app_purchase_android, local_auth_android,
shared_preferences_android, url_launcher_android, video_player_android.
Robolectric 4.17 adds support for Android SDK 37 (API 37), which is
needed before plugins can move their compile/target SDK to 37.

This depends on the --add-opens JVM arguments added in the previous
commit; without them Robolectric 4.17 fails most tests on JDK 17+.

video_player_android additionally needs jsr305 on the unit test
compile classpath. Robolectric 4.17 added a
@javax.annotation.concurrent.GuardedBy annotation to ShadowView (the
superclass of ShadowSurfaceView, which PlatformVideoViewTest uses), but
doesn't declare a dependency on jsr305, the library that defines it.
javac emits a -Xlint:classfile warning when a referenced class carries
an annotation it can't resolve, and the example app compiles the plugin
with -Xlint:all -Werror, so the test compile fails without it.
Keeps the example apps' Robolectric version in sync with the plugins.
The video_player_android example app has its own unit tests, so it
also gets Robolectric's recommended --add-opens JVM arguments, which
4.17 requires on JDK 17+.
Generated with:
  dart run script/tool/bin/flutter_plugin_tools.dart update-release-info \
    --version=minimal --base-branch=<PR base> \
    --changelog="Updates Robolectric to 4.17 and adds the JVM arguments it requires for unit tests."

The video_player entry (example-app-only change, NEXT section) was
reworded by hand since that example gets no new JVM arguments.
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 27, 2026
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates Robolectric to version 4.17 and adds the required JVM arguments (--add-opens) for JDK 17+ compatibility across multiple Android packages and their examples. It also adds the jsr305 dependency to video_player_android to resolve a compiler warning. Feedback on the changes notes that the video_player example app's build.gradle.kts updates Robolectric to 4.17 but is missing the corresponding JVM arguments, which will cause unit test failures on JDK 17+.

dependencies {
testImplementation("junit:junit:4.13.2")
testImplementation("org.robolectric:robolectric:4.16")
testImplementation("org.robolectric:robolectric:4.17")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The example app's unit tests are being updated to Robolectric 4.17, but the required JVM arguments for running with Java 17+ (using --add-opens) have not been added to this build.gradle.kts file, unlike the other packages and examples in this PR.\n\nWithout these JVM arguments, running the unit tests on JDK 17 or higher will fail due to reflective access restrictions. Please add the testOptions block with the recommended JVM arguments to the android block of this file.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant