Skip to content

Migrate template to Gradle 6.7 and AGP 4.1.0 #70808

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 17 commits into from
Nov 20, 2020
Merged

Conversation

blasten
Copy link

@blasten blasten commented Nov 19, 2020

Description

Makes the plugin and the tool compatible with the latest release of AGP version, and Gradle.
Migrates the template files for apps, plugins and modules.
Migrates files in the Flutter repo.

Related Issues

Fixes #58247
Fixes #49438

Tests

I added the following tests: unit & e2e 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 read the Tree Hygiene wiki page, which explains my responsibilities.
  • 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

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) d: examples Sample code and demos c: contributor-productivity Team-specific productivity, code health, technical debt. tool Affects the "flutter" command-line tool. See also t: labels. labels Nov 19, 2020
@google-cla google-cla bot added the cla: yes label Nov 19, 2020
@Zazo032
Copy link
Contributor

Zazo032 commented Nov 19, 2020

@blasten latest available versions right now are 6.7.1 for Gradle and 4.1.1 for AGP, just in case you want to update it to latest available patch

lintOptions {
disable 'InvalidPackage'
}
compileSdkVersion 30
Copy link
Member

Choose a reason for hiding this comment

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

this is ok but just for my understanding, this is orthogonal to a agp move right?

Copy link
Author

Choose a reason for hiding this comment

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

that's true

@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
Copy link
Member

Choose a reason for hiding this comment

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

can you elaborate? Or is this just to save time since no one is shipping it?

Copy link
Author

Choose a reason for hiding this comment

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

R8 has become the default in this AGP version. Having this causes a warning.

Copy link
Member

Choose a reason for hiding this comment

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

got it, thanks

import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), "flavor").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
Copy link
Member

Choose a reason for hiding this comment

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

related?

Copy link
Author

Choose a reason for hiding this comment

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

it's a small clean up. This isn't used by the test, and was causing some warnings.

Copy link
Member

Choose a reason for hiding this comment

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

ok

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.

woohoo! Amazing

// This way, custom Proguard rules can be configured as needed.
proguardFiles project.android.getDefaultProguardFile("proguard-android.txt"), flutterProguardRules, "proguard-rules.pro"
}
String flutterProguardRules = Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools",
Copy link
Member

Choose a reason for hiding this comment

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

is that what the enable r8 thing is? We're just making it unconditional?

Copy link
Author

@blasten blasten Nov 20, 2020

Choose a reason for hiding this comment

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

This is one is about removing the need to make this conditional via a Flutter tool flag. That isn't needed. Users shouldn't disable this in release, but if they really want, they can always do it in build.gradle.

String flutterProguardRules = Paths.get(flutterRoot.absolutePath, "packages", "flutter_tools",
"gradle", "flutter_proguard_rules.pro")
project.android.buildTypes {
release {
Copy link
Member

Choose a reason for hiding this comment

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

what levers are we giving for custom build types?

Copy link
Author

Choose a reason for hiding this comment

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

levers?

Copy link
Member

Choose a reason for hiding this comment

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

when users create custom types, we should document what the right approach is to have the correct default settings associated. e.g. recommend

production {
     initWith release         
}

rather than making one from scratch

Copy link
Author

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 are doing anything special, other than profile.

release is an official build type provided by the Android plugin. I think the Flutter docs can link to https://developer.android.com/studio/build/build-variants.

return target
}

// In AGP 4.0, the Android linter task depends on all the JAR tasks containing `libapp.so`.
Copy link
Member

Choose a reason for hiding this comment

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

Didn't understand this sentence :)

Copy link
Author

Choose a reason for hiding this comment

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

I changed the sentence a bit. #58247 (comment)

// 3. Otherwise, the equivalent Flutter variant is `release`.
String variantBuildMode = buildModeFor(libraryVariant.buildType)
if (buildModeFor(appProjectVariant.buildType) != variantBuildMode) {
return
Copy link
Member

Choose a reason for hiding this comment

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

Can we print a message here? I always found the mismatch error a bit cryptic.

Copy link
Author

@blasten blasten Nov 20, 2020

Choose a reason for hiding this comment

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

This is during configuration phase. It could be quite spammy, and not very meaningful for debugging. What's the user story?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe I'm thinking of something else. In Android Studio, open build variants tab in case of gradle subproject integration, pick one variant for the app and another variant for the flutter module.

'To learn more, see: https://developer.android.com/studio/build/shrink-code',
);
hide: true,
help: 'This flag is deprecated.'
Copy link
Member

Choose a reason for hiding this comment

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

Describe a bit more what now happens

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
Copy link
Member

Choose a reason for hiding this comment

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

can we add another test to make sure the whole thing builds with gradle 5 / agp 3?

Copy link
Author

Choose a reason for hiding this comment

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

that is already the case in the customer tests

Copy link
Member

Choose a reason for hiding this comment

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

which customer tests are you referring to?

Copy link
Author

Choose a reason for hiding this comment

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

https://github.com/flutter/tests/tree/master/registry - Although, it looks like we don't build apk in any of those. I will add one that does it.

Copy link
Author

Choose a reason for hiding this comment

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

Filed #70964. Gradle 5.* is currently tested by building the Flutter Gallery demo app.

@xster
Copy link
Member

xster commented Nov 20, 2020

@csells could be worth calling this out on the next stable blog

@blasten blasten requested a review from xster November 20, 2020 16:41
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.

LGTM 🤞

@blasten blasten merged commit 8e73bab into flutter:master Nov 20, 2020
@blasten blasten deleted the gradle_6_0 branch November 20, 2020 21:05
@amirh
Copy link
Contributor

amirh commented Nov 23, 2020

This broke flutter/plugins, see: https://cirrus-ci.com/task/6538283054268416

@gustav3d
Copy link

So instead of fiximg the boken plugin https://cirrus-ci.com/task/6538283054268416, you revert this?!

@amirh
Copy link
Contributor

amirh commented Nov 23, 2020

@gustav3d per https://github.com/flutter/flutter/wiki/Tree-hygiene if a commit breaks a tree it should be first reverted, no questions asked, then it should be re-landed with the issue figured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: accessibility Accessibility, e.g. VoiceOver or TalkBack. (aka a11y) c: contributor-productivity Team-specific productivity, code health, technical debt. d: examples Sample code and demos tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flutter build apk fails on an app using Android Gradle plugin 4.0 Upgrade the Gradle version in the project template
5 participants