Repository: flutter
Issue: Flutter Gradle Plugin (`flutter.gradle`) is not taking advantage of Gradle's Configuration Avoidance API
Labels: c: new feature,platform-android,tool,t: gradle,has reproducible steps,P2,found in release: 3.7,team-android,triaged-android

## Steps to Reproduce

1. `flutter create` a simple app
3. Run a debug Gradle build in the `android` directory

    ```console
    $ ./gradlew :app:tasks
    ```


**Expected results:**

I expect no tasks to be created immediately, to follow Gradle's best practices ([Task Configuration Avoidance](https://docs.gradle.org/current/userguide/task_configuration_avoidance.html) 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](https://github.com/flutter/flutter/tree/master/packages/flutter_tools/gradle/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 run`s on Android).


### How to see what tasks are created immediately in Gradle?

Use [Build Scans](https://scans.gradle.com/). To create a scan for the Gradle build:

```console
$ ./gradlew :app:tasks --scan
```

See an example Build Scan demonstrating this: [link](https://scans.gradle.com/s/tszsdviobbpsw/performance/configuration?details=code-unit-com.android.internal.application!:app&openScriptsAndPlugins=WyJjb2RlLXVuaXQtY29tLmFuZHJvaWQuaW50ZXJuYWwuYXBwbGljYXRpb24iXQ).

![Screenshot 2023-01-25 at 11 54 51 PM](https://user-images.githubusercontent.com/40357511/214710248-7d862add-61e0-475e-a32f-0bbbca68302c.png)



</details>

<details>
  <summary>Logs</summary>


<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
$ 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.
```

</details>