Skip to content

Flutter Gradle Plugin (flutter.gradle) is not taking advantage of Gradle's Configuration Avoidance API #119196

Description

@bartekpacia

Steps to Reproduce

  1. flutter create a simple app

  2. Run a debug Gradle build in the android directory

    $ ./gradlew :app:tasks

Expected results:

I expect no tasks to be created immediately, to follow Gradle's best practices (Task Configuration Avoidance in this case).

Tasks such as compileFlutterBuildRelease or packBuildsFlutterLibRelease sound like they should only be configured when building an app in release mode, but instead, they're created in every Gradle build.

These tasks are registered in flutter.gradle. According to Gradle, the lazy project.tasks.register() method should be used instead of the eager project.tasks.create() method.

Actual results:

Some tasks are created immediately on every Gradle invocation (so basically every time someone flutter runs on Android).

How to see what tasks are created immediately in Gradle?

Use Build Scans. To create a scan for the Gradle build:

$ ./gradlew :app:tasks --scan

See an example Build Scan demonstrating this: link.

Screenshot 2023-01-25 at 11 54 51 PM

Logs
$ flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale en-PL)
    • Flutter version 3.3.10 on channel stable at /Users/bartek/fvm/versions/3.3.10
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (6 weeks ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at /Users/bartek/androidsdk
    • Platform android-33, build-tools 33.0.1
    • ANDROID_HOME = /Users/bartek/androidsdk
    • Java binary at: /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (version 2022.1)
    • Android Studio at /Users/bartek/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/221.6008.13.2211.9477386/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
    • IntelliJ at /Users/bartek/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 71.3.6
    • Dart plugin version 223.8214.16

[✓] IntelliJ IDEA Ultimate Edition (version 2022.3.1)
    • IntelliJ at /Users/bartek/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.8214.52/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.74.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.58.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.1 22C65 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 109.0.5414.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Activity

  1. darshankawar commented on Jan 26, 2023

    @darshankawar
    Member

    Thanks for the report. Seeing same behavior as reported. Will keep this issue open and label for team's thoughts on current behavior.

    stable, master flutter doctor -v
    [!] Flutter (Channel stable, 3.7.0, on macOS 12.2.1 21D62 darwin-x64, locale
        en-GB)
        • Flutter version 3.7.0 on channel stable at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision b06b8b2710 (28 hours ago), 2023-01-23 16:55:55 -0800
        • Engine revision b24591ed32
        • Dart version 2.19.0
        • DevTools version 2.20.1
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    [!] Flutter (Channel master, 3.7.0-27.0.pre.25, on macOS 12.2.1 21D62
        darwin-x64, locale en-GB)
        • Flutter version 3.7.0-27.0.pre.25 on channel master at
          /Users/dhs/documents/fluttersdk/flutter
        ! Warning: `flutter` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
          your current Flutter SDK checkout at
          /Users/dhs/documents/fluttersdk/flutter. Consider adding
          /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
        ! Warning: `dart` on your path resolves to
          /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
          current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
          Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
          of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision c9affdba9d (3 hours ago), 2023-01-25 21:25:02 -0800
        • Engine revision 8f1e5dc1b1
        • Dart version 3.0.0 (build 3.0.0-157.0.dev)
        • DevTools version 2.20.1
        • If those were intentional, you can disregard the above warnings; however
          it is recommended to use "git" directly to perform update checks and
          upgrades.
    
    [!] Xcode - develop for iOS and macOS (Xcode 12.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        ! Flutter recommends a minimum Xcode version of 13.
          Download the latest version or update via the Mac App Store.
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] VS Code (version 1.62.0)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.21.0
    
    [✓] Connected device (5 available)
        • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
        • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
          ios            • iOS 14.4.1 18D61
        • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
          ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
        • macOS (desktop)            • macos                                    •
          darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
        • Chrome (web)               • chrome                                   •
          web-javascript • Google Chrome 98.0.4758.80
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    ! Doctor found issues in 1 category.
    
    
    
    
  2. added
    platform-androidAndroid applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    t: gradle"flutter build" and "flutter run" on Android
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Jan 26, 2023
  3. reidbaker commented on Jan 26, 2023

    @reidbaker
    Contributor

    Can you describe some of the benefit developers will get if this work is done?

  4. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 26, 2023
  5. bartekpacia commented on Jan 26, 2023

    @bartekpacia
    MemberAuthor

    Sure.

    Overall, it ain't gonna be that much of a benefit, but I think it's still worth it (if it's merely replacing a few method calls).

    For example, here's what motivated me to create this issue: I was optimizing my app's build times on Android and was using Gradle's Build Scan feature for this. I followed the Gradle tutorial I linked above. I saw that a few Flutter's Gradle tasks (e.g for releasing - which happens quite rarely compare to, say, assembleDebug) are configured on each build, and initially I though that I mesed something up in my app's code (before I checked Flutter's Gradle plugin code).

    There should also be some performance benefit, but I didn't measure it. I guess it'll be negligible for most people on modern hardware.

    And we'll be following Gradle best practices. Hooray.

    I can contribute this if you agree with this issue.

  6. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 26, 2023
  7. reidbaker commented on Jan 26, 2023

    @reidbaker
    Contributor

    Yeah I am open to a pull request if you decide to contribute.

  8. added
    P2Important issues not at the top of the work list
    on Jan 26, 2023
  9. gnprice commented on Mar 26, 2023

    @gnprice
    Member

    For cross-reference: #122289 was (and #122290 fixed) a case of this that was in the flutter create templates rather than in the Flutter Gradle plugin, and that was therefore causing warnings for developers.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilityfound in release: 3.7Found to occur in 3.7has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions