Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webview_flutter_android] Build Error occured, fixed at line 89 and 200. #9012

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

method76
Copy link

@method76 method76 commented Apr 6, 2025

[Issue Summary]

  • Gradle debug build of this plugin is failed for some line of codes are considered errors.

[Reason]

  • When put the same lambda in the removeCallbacks, it's not recognized as the same object and not removed.

[How is it Fixed]

  • 2 lines of codes are simply fixed.

[Modified File Path]

  • /webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt
  • /webview_flutter/webview_flutter_android/CHANGELOG.md
  • /webview_flutter/webview_flutter_android/pubspec.yaml

[Issue Details]

In Kotlin, we can implicitly convert the lambda to a Runnable (SAM conversion) and pass it over, but the problem is that when we put the same lambda in the removeCallbacks, it is not recognized as the same object and cannot be removed.

// original code (at 89 line and 201 line)
handler.removeCallbacks { this.releaseAllFinalizedInstances() }

// modified code (replaced same 1 line code x 2 to with below 2 line codes x 2)
val runnable = Runnable { this.releaseAllFinalizedInstances() }
handler.removeCallbacks(runnable)

[Test Exemption related] Just simple modification, so didn't add any additional unit test code.

  • Modified 1 line of code x 2, passed lint, and the plugin was successfully built.

[Before] Build error message has captured below.

err

[After] The build error is resolved and the build is successful as like below.

error_resol

Replace this paragraph with a description of what this PR is changing or adding, and why. Consider including before/after screenshots.

List which issues are fixed by this PR. You must list at least one issue.

Pre-Review Checklist

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

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 3

method76 added 2 commits April 6, 2025 15:55
- error reason: Put the same lambda in the removeCallbacks, not recognized as the same object and not removed.
- error reason: Put the same lambda in the removeCallbacks, not recognized as the same object and not removed.
@method76 method76 requested a review from bparrishMines as a code owner April 6, 2025 07:24
@flutter-dashboard
Copy link

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.

Copy link

google-cla bot commented Apr 6, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@stuartmorgan-g
Copy link
Contributor

[Test Exemption related] Just simple modification, so didn't add any additional unit test code.

That is not one of the test exemption criteria. If this is fixing an issue, it needs some kind of test.

This step is checked, but not completed. We need a detailed issue report explaining how to reproduce this; the PR just says to do a debug build, but we do debug builds as part of our CI, so there must be other steps or configuration necessary to reproduce the problem.

Knowing how to reproduce it would inform how to test this in CI.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft April 8, 2025 19:09
@@ -86,7 +86,8 @@ class AndroidWebkitLibraryPigeonInstanceManager(
*/
var clearFinalizedWeakReferencesInterval: Long = 3000
set(value) {
handler.removeCallbacks { this.releaseAllFinalizedInstances() }
val runnable = Runnable { this.releaseAllFinalizedInstances() }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is bypassing the warning rather than fixing what the warning is flagging, which is that this will not remove the listener added on line 96.

The goal with warnings is to address the cause of the warning, rather than to silence the warning without fixing the underlying problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

My Kotlin might be slightly off but I think the intended line should be:

handler.removeCallbacks(releaseAllFinalizedInstances)

And the Handler.postDelayed below needs to be updated as well.

@bparrishMines
Copy link
Contributor

@method76 Thanks for finding this! In this PR you are changing generated code, so we can't accept this as is. I created #9034 to update the pigeon code generator with the fix for this warning. After that lands, the plugin just needs to regenerate code with the latest version of pigeon.

Also, the build error is caused by your app configuration where you specifically have warning as errors and have enabled the ImplicitSamInstance lint. The app should still build when the lint is disabled.

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.

3 participants