8000 Generate projects using the new Android embedding by blasten · Pull Request #41666 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Generate projects using the new Android embedding #41666

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

Merged
merged 5 commits into from
Oct 4, 2019

Conversation

blasten
Copy link
@blasten blasten commented Oct 1, 2019

Description

Generate projects using the new Android embedding. This feature is under a flag, so to generate new projects, run:

flutter config --enable-new-android-embedding
flutter create -t <project-type> <destination>

Pending feature: #41757

Related Issues

Fixes #33161
Fixes #35509

Tests

Unit tests

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added the tool Affects the "flutter" command-line tool. See also t: labels. label Oct 1, 2019
@blasten blasten changed the title WIP Generate projects using the new Android embedding Oct 1, 2019
@blasten blasten force-pushed the new_embedding branch 2 times, most recently from fa4fc85 to fbfccc6 Compare October 1, 2019 06:00
@flutter flutter deleted a comment from fluttergithubbot Oct 1, 2019
@codecov
Copy link
codecov bot commented Oct 2, 2019

Codecov Report

Merging #41666 into master will increase coverage by 0.68%.
The diff coverage is 88.4%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #41666      +/-   ##
==========================================
+ Coverage   58.69%   59.37%   +0.68%     
==========================================
  Files         194      193       -1     
  Lines       18934    18936       +2     
==========================================
+ Hits        11113    11243     +130     
+ Misses       7821     7693     -128
Flag Coverage Δ
#flutter_tool 59.37% <88.4%> (+0.68%) ⬆️
8000
Impacted Files Coverage Δ
packages/flutter_tools/lib/src/android/gradle.dart 75.8% <ø> (ø) ⬆️
...ackages/flutter_tools/lib/src/commands/create.dart 72.63% <100%> (+0.08%) ⬆️
packages/flutter_tools/lib/src/project.dart 87.07% <100%> (+0.43%) ⬆️
packages/flutter_tools/lib/src/features.dart 83.33% <50%> (-1.45%) ⬇️
packages/flutter_tools/lib/src/plugins.dart 86.84% <87.17%> (+5.74%) ⬆️
...ckages/flutter_tools/lib/src/platform_plugins.dart 73.26% <91.3%> (+52.01%) ⬆️
packages/flutter_tools/lib/src/ios/mac.dart 40.49% <0%> (-13.4%) ⬇️
...ackages/flutter_tools/lib/src/commands/config.dart 73.33% <0%> (-13.34%) ⬇️
...ckages/flutter_tools/lib/src/reporting/events.dart 93.65% <0%> (-3.18%) ⬇️
packages/flutter_tools/lib/src/version.dart 91.9% <0%> (-1.43%) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db9ad60...23859ea. Read the comment docs.

@blasten blasten force-pushed the new_embedding branch 2 times, most recently from 35c96bb to 76b3f8b Compare October 2, 2019 05:50
@blasten blasten added platform-android Android applications specifically and removed work in progress; do not review labels Oct 2, 2019
Copy link
Member
@xster xster left a comment

Choose a reason for hiding this comment

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

Matt should review but general LGTM

@@ -30,4 +29,8 @@
</intent-filter>
</activity>
</application>
{{#useNewAndroidEmbedding}}
<!-- Don't delete this comment.
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can leave some breadcrumbs for future maintainers to realize what this is for. Can be sparse since it'll be in users' projects.

Copy link
Author

Choose a reason for hiding this comment

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

I just added a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should find another approach to this.

Copy link
Author

Choose a reason for hiding this comment

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

@matthew-carroll any suggestion?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify the precise reason that we need this information?

Copy link
Author

Choose a reason for hiding this comment

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

app1 uses the old embedding
app2 uses the new embedding.

This hint is used by the tool to generate the new plugin registrant for app2.

Copy link
Member
@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

lgtm w/ nits

8000
@@ -63,9 +63,8 @@ class Plugin {
}
if (pluginYaml != null && pluginYaml['platforms'] != null) {
return Plugin._fromMultiPlatformYaml(name, path, pluginYaml);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to remove this else statement? Unless we have a series of if-return, if-return, if-return, return then the if-else looks more appropriate to me.

Copy link
Author

Choose a reason for hiding this comment

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

This is the last statement and the else statement is redundant/unnecessary nesting.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. I wouldn't call it redundant, but it's your call.

android:name="flutterProjectType"
android:value="module" />
</application>
<!-- Don't delete this comment.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should have this.

}

@Override
public void onMethodCall(MethodCall call, Result result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we generate 2 files instead of 1? I think we should incentivize channel comms in a dedicated file so that people might actually unit test message serialization.

Copy link
Author

Choose a reason for hiding this comment

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

The templates in this directory is used for plugin projects that don't use the new embedding. However, if 1 file is applicable to the new embedding only, then we would need to duplicate the directory or refactor the code to exclude certain files. I can follow up with this later, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

The top of this template says "implements FlutterPlugin", which is the new embedding.

Copy link
Author
@blasten blasten Oct 3, 2019

Choose a reason for hiding this comment

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

This file contains the code for both embedding. see {{#useNewAndroidEmbedding}} and {{^useNewAndroidEmbedding}} sections.

@blasten
Copy link
Author
blasten commented Oct 4, 2019

@matthew-carroll I reworked the detection mechanism using <meta-data> instead of a comment. Please take another look when you get a chance.

Copy link
Contributor
@matthew-carroll matthew-carroll left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for reworking.

for (xml.XmlElement metaData in document.findAllElements('meta-data')) {
final String name = metaData.getAttribute('android:name');
if (name == 'flutterEmbedding') {
return metaData.getAttribute('android:value');
Copy link
Contributor

Choose a reason for hiding this comment

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

It would probably be a good idea to check accepted values here and throw an appropriate error if a bad value is passed in.

@blasten blasten merged commit 5961bcc into flutter:master Oct 4, 2019
@blasten blasten deleted the new_embedding branch October 4, 2019 13:23
import io.flutter.plugin.common.MethodChannel.Result;

/** {{pluginClass}} */
public class {{pluginClass}} implements FlutterPlugin, MethodCallHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Plugins generated with this template will not be backward compatible with apps that are using the v1 embedding.

Should we have a registerWith here as well? at least until we are ready to deprecate the v1 embedding?

@blasten @xster @matthew-carroll @mklim

Copy link
Author

Choose a reason for hiding this comment

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

so far, the plan is to exit the tool if an app using the v1 embedding attempts to use a plugin using the v2 embedding. Issue: #43779

Copy link
Contributor

Choose a reason for hiding this comment

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

Offline discussion - we should probably see enough adoption of v2 embedding in Flutter apps and be willing to deprecate it before we make it easy to create plugins that do not support the v1 embedder.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also agree with that conclusion. For at least 2-3 quarters, I would recommend generating backward compatible plugins with appropriate comment instructions.

Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
* Generate projects using the new Android embedding

* Add comment about usesNewEmbedding:true

* Feedback

* Rework way to detect new embedding in new apps
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update flutter tools for new Android plugins API Update flutter create templates and flutter repo to use new Android embedding
7 participants
0