flutter/packages/flutter_tools/lib/src/android
chunhtai 82ecbb5cbd
Refactor gradle task runner to share error handler code (#159452)
fixes https://github.com/flutter/flutter/issues/153893

## Pre-launch Checklist

- [ ] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [ ] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [ ] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [ ] I signed the [CLA].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: Gray Mackall <34871572+gmackall@users.noreply.github.com>
2024-12-13 18:51:20 +00:00
..
migrations Fix use of deprecated buildDir in Android templates/tests/examples (#157560) 2024-11-06 21:34:23 +00:00
adb.dart Migrate flutter_tool tool helper files to null safety (#78845) 2021-03-23 10:02:59 -07:00
android_builder.dart Improves output file path logic in Android analyze (#136981) 2023-11-16 22:59:02 +00:00
android_console.dart Migrate android_console to null safety (#78923) 2021-03-24 15:18:00 -07:00
android_device_discovery.dart include exception details in tool exit displayed when adb call fails (#147498) 2024-04-30 17:38:21 +00:00
android_device.dart Move platform-specific log-reading implementation details from ResidentRunner/FlutterDevice to DeviceLogReader implementations (#156181) 2024-11-14 21:29:30 +00:00
android_emulator.dart Enable private field promotion for flutter_tools (#134474) 2023-09-12 20:20:04 +00:00
android_sdk.dart Implementing null-aware operators throughout the repository (#143804) 2024-02-23 19:02:22 +00:00
android_studio_validator.dart [tool] In flutter doctor -v, warn when Android Studio version could not be detected. (#126395) 2023-06-01 14:51:30 +00:00
android_studio.dart [tool] fix android studio preview's version parsing (#156293) 2024-10-16 15:56:31 +00:00
android_workflow.dart doctor: make JDK validation message more descriptive (#157280) 2024-11-23 00:27:18 +00:00
android.dart Migrate flutter_tool tool helper files to null safety (#78845) 2021-03-23 10:02:59 -07:00
application_package.dart flutter-tool: enum cleanup (#124760) 2023-04-14 01:55:05 +00:00
build_validation.dart Switch to more reliable flutter.dev link destinations in the tool (#150587) 2024-06-26 23:30:39 +00:00
deferred_components_gen_snapshot_validator.dart Remove unnecessary null checks in flutter_tool (#118857) 2023-01-23 21:43:08 +00:00
deferred_components_prebuild_validator.dart Add support for Gradle Kotlin DSL (#140744) 2024-01-12 02:20:06 +00:00
deferred_components_validator.dart Reland "if chains → switch expressions" (#148634) 2024-05-20 17:43:00 +00:00
gradle_errors.dart Fixed typos (#159331) 2024-12-05 16:54:09 +00:00
gradle_utils.dart Upgrade templates to AGP 8.7/Gradle 8.10.2 (#157872) 2024-10-30 18:54:06 +00:00
gradle.dart Refactor gradle task runner to share error handler code (#159452) 2024-12-13 18:51:20 +00:00
java.dart doctor: make JDK validation message more descriptive (#157280) 2024-11-23 00:27:18 +00:00
README.md [Re-re-land] Enforce a policy on supported Gradle, Java, AGP, and KGP versions (#143341) 2024-02-13 15:44:17 +00:00

Flutter Tools for Android

This section of the Flutter repository contains the command line developer tools for building Flutter applications on Android. What follows are some notes about updating this part of the tool.

Updating Android dependencies

The Android dependencies that Flutter uses to run on Android include the Android NDK and SDK versions, Gradle, the Kotlin Gradle Plugin, and the Android Gradle Plugin (AGP). The template versions of these dependencies can be found in gradle_utils.dart.

Follow the guides below when*...

Updating the template version of...

The Android SDK & NDK

All of the Android SDK/NDK versions noted in gradle_utils.dart (compileSdkVersion, minSdkVersion, targetSdkVersion, ndkVersion) versions should match the values in Flutter Gradle Plugin (FlutterExtension), so updating any of these versions also requires an update in flutter.groovy.

When updating the Android compileSdkVersion, minSdkVersion, or targetSdkVersion, make sure that:

  • Framework integration & benchmark tests are running with at least that SDK version.
  • Flutter tools tests that perform String checks with the current template SDK versions are updated (you should see these fail if you do not fix them preemptively).

Also, make sure to also update to the same version in the following places:

  • The version in the buildscript block in packages/flutter_tools/gradle/src/main/groovy/flutter.groovy.
  • The version in the buildscript block in packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts.
  • The version in the dependencies block in packages/flutter_tools/gradle/build.gradle.kts.

Gradle

When updating the Gradle version used in project templates (templateDefaultGradleVersion), make sure that:

  • Framework integration & benchmark tests are running with at least this Gradle version.
  • Flutter tools tests that perform String checks with the current template Gradle version are updated (you should see these fail if you do not fix them preemptively).

The Kotlin Gradle Plugin

When updating the Kotlin Gradle Plugin (KGP) version used in project templates (templateKotlinGradlePluginVersion), make sure that the framework integration & benchmark tests are running with at least this KGP version.

For information about the latest version, check https://kotlinlang.org/docs/releases.html#release-details.

The Android Gradle Plugin (AGP)

When updating the Android Gradle Plugin (AGP) versions used in project templates (templateAndroidGradlePluginVersion, templateAndroidGradlePluginVersionForModule), make sure that:

  • Framework integration & benchmark tests are running with at least this AGP version.
  • Flutter tools tests that perform String checks with the current template AGP versions are updated (you should see these fail if you do not fix them preemptively).

A new version becomes available for...

Gradle

When new versions of Gradle become available, make sure to:

  • Check if the maximum version of Gradle that we support (maxKnownAndSupportedGradleVersion) can be updated, and if so, take the necessary steps to ensure we are testing this version in CI.
  • Check that the Java version that is one higher than we currently support (oneMajorVersionHigherJavaVersion) based on current maximum supported Gradle version is up-to-date.
  • Update the _javaGradleCompatList that contains the Java/Gradle compatibility information known to the tool.
  • Update the test cases in gradle_utils_test.dart that test compatibility between Java and Gradle versions (relevant tests should fail if you do not fix them preemptively, but should also be marked inline).
  • Update the test cases in create_test.dart that test for a warning for Java/Gradle incompatibilities as needed (relevant tests should fail if you do not fix them preemptively).

For more information about the latest version, check https://gradle.org/releases/.

The Android Gradle Plugin (AGP)

When new versions of the Android Gradle Plugin become available, make sure to:

  • Update the maximum version of AGP that we know of (maxKnownAgpVersion).
  • Check if the maximum version of AGP that we support (maxKnownAndSupportedAgpVersion) can be updated, and if so, take the necessary steps to ensure that we are testing this version in CI.
  • Update the _javaAgpCompatList that contains the Java/AGP compatibility information known to the tool.
  • Update the test cases in gradle_utils_test.dart that test compatibility between Java and AGP versions (relevant tests should fail if you do not fix them preemptively, but should also be marked inline).
  • Update the test cases in create_test.dart that test for a warning for Java/AGP incompatibilities as needed (relevant tests should fail if you do not fix them preemptively).

For information about the latest version, check https://developer.android.com/studio/releases/gradle-plugin#updating-gradle.

* There is an ongoing effort to reduce these steps; see https://github.com/flutter/flutter/issues/134780.