[flutter_webview] Migrate to the new embedding #2169
Conversation
I haven't decided how to handle the fact that we need a new version of the engine for this work with the new embedding yet. Naively we can try to check the version and then log the error but that's not great. Without the engine patch text input doesn't work on older Android versions at all with the new embedding. |
android.useAndroidX=trueandroid.enableR8=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a newline here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, thank you.
I believe this PR is ready to merge, after review. The latest commit added the new e2e tests and updated the pubspec.yaml. ETA: On second thought, @amirh we should probably sync up about how to define "minimum version" here. The new embedding is only going to be functional in flutter versions after flutter/engine#13015 lands. Can we get the flutter version at runtime from the Java files? We may want to log an error if the new embedding is used with an older version of flutter. |
@@ -5,6 +5,7 @@ version: 1.0.1 | |||
|
|||
environment: | |||
sdk: ">=2.0.0-dev.68.0 <3.0.0" | |||
flutter: ">=1.9.1+hotfix.2 <2.0.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why you picked hotfix 2? is the intention to bump it to the next stable once it's there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My local branch is out of date, I just meant to pick the most recent stable. Changed it to .4
.
I think so, especially since we'll need the v2 Registrant.
@@ -0,0 +1 @@ | |||
include ':app' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was automatically created by the tool at some point. I'll revert it since it's not related to this PR.
// Copyright 2018 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
package io.flutter.plugins.webviewflutterexample; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add license header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
public class WebViewFlutterPlugin implements FlutterPlugin { | ||
private @Nullable FlutterCookieManager flutterCookieManager; | ||
|
||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd think we don't want to direct users to do that. They should rely on the generated registrant (if it's not there it probably means their engine is old enough to not run this plugin properly anyway)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworded. I linked to the tracking issue here and removed the reference to MainActivity.
super.onCreate(savedInstanceState); | ||
GeneratedPluginRegistrant.registerWith(this); | ||
public void configureFlutterEngine(FlutterEngine flutterEngine) { | ||
flutterEngine.getPlugins().add(new WebViewFlutterPlugin()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a TODO to remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
/** | ||
* Java platform implementation of the webview_flutter plugin. | ||
* | ||
* <p>Instantiate this in an add to app scenario to gracefully handle activity and context changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure whether we want to include these kind of instructions as users shouldn't really need to do that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reworded.
|
||
Log.e(TAG, "The containerView has changed while the proxyAdapterView exists."); | ||
if (containerView != null) { | ||
setInputConnectionTarget(proxyAdapterView); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work? (if so should we log an error?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this does work from my testing. Semantically this seems "wrong" to me, because we're changing the view after it's already been launched. I'm worried that there may be other bugs under the hood. But it is spammy to log this without a confirmed error. I downgraded to WARNING
.
// Use FlutterCookieManager#registerWith instead. | ||
FlutterCookieManager(BinaryMessenger messenger) { | ||
methodChannel = new MethodChannel(messenger, "plugins.flutter.io/cookie_manager"); | ||
methodChannel.setMethodCallHandler(this); | ||
} | ||
|
||
static void registerWith(BinaryMessenger messenger) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could completely remove this method...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess so, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as it was all nites (modulo nits :) )
This depends on a new bugfix on the engine for text input to work with the new embedding (flutter/engine#13015). This also introduces some interesting and strange new failure cases. With the new embedding, a FlutterView can be attached and detached from the plugin at any point. It "should never" but technically can happen that the plugin gets into a state where there is an active proxy adapter view but no valid FlutterView to use for input proxying. For now I've mostly added error logs and guards against NPEs detecting whenever we've gotten into one of this situations. But I think we should probably rigorously test this in an a2a specific situation to truly vet for a2a support. DO NOT MERGE until we can land tests for this.
- Add the required lifecycle files into the dynamic Gradle inclusion script - Convert the FlutterDriver test to use the e2e package - Update the pubspec and CHANGELOG, including incrementing the minimum SDK version
This depends on a new bugfix on the engine for text input to work with the new embedding (flutter/engine#13015).
This depends on a new bugfix on the engine for text input to work with the new embedding (flutter/engine#13015).
Description
This depends on a new bugfix on the engine for text input to work with
the new embedding (flutter/engine#13015).
This also introduces some interesting and strange new failure cases.
With the new embedding, a FlutterView can be attached and detached from
the plugin at any point. It "should never" but technically can happen
that the plugin gets into a state where there is an active proxy adapter
view but no valid FlutterView to use for input proxying. For now I've
mostly added error logs and guards against NPEs detecting whenever we've
gotten into one of this situations. But I think we should probably
rigorously test this in an a2a specific situation to truly vet for a2a
support.
Related Issues
Fixes flutter/flutter#41851.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]
). This will ensure a smooth and quick review process.///
).flutter analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?