Skip to content

Remove code that manipulates AGP tasks by discovering them via their name #166550

Open
1 of 6 issues completed

Description

@gmackall

The Flutter Gradle plugin is (by necessity) built on top of AGP.

AGP today has exposed APIs designed for extending it https://developer.android.com/build/extend-agp#variant-api-artifacts-tasks.

This was not the case when the Flutter Gradle plugin was written. Instead, we discovered tasks that AGP added by guessing their name as a string and then doing things with them (typically making them depend on the Flutter tasks that we were adding). We should remove this string based guessing, and migrate to their intended API.

e.g.

Task packageAssets
Task cleanPackageAssets
try {
packageAssets = project.tasks.named("package${variant.name.capitalize()}Assets").get()
} catch (UnknownTaskException ignored) {
packageAssets = null
}
try {
cleanPackageAssets = project.tasks.named("cleanPackage${variant.name.capitalize()}Assets").get()
} catch (UnknownTaskException ignored) {
cleanPackageAssets = null
}

The good news is that I think these attempts to get tasks might already be failing? They seemed to be always null in my brief testing, which means it would be easy to remove them. But that is a guess.

Activity

  1. gmackall commented on Apr 3, 2025

    @gmackall
    MemberAuthor

    Making a full list

    Tasks that I believe AGP names (but am unsure)

    Task packageAssets
    Task cleanPackageAssets
    try {
    packageAssets = project.tasks.named("package${variant.name.capitalize()}Assets").get()
    } catch (UnknownTaskException ignored) {
    packageAssets = null
    }
    try {
    cleanPackageAssets = project.tasks.named("cleanPackage${variant.name.capitalize()}Assets").get()
    } catch (UnknownTaskException ignored) {
    cleanPackageAssets = null
    }

    def tasksToCheck = [
    "compress${variant.name.capitalize()}Assets",
    "bundle${variant.name.capitalize()}Aar",
    "bundle${variant.name.capitalize()}LocalLintAar"
    ]

    Tasks that I believe WE have named (but am unsure - but if correct we could move to a typesafe approach easily)

    Task moduleProjectTask = moduleProject.tasks.named("assembleAar$variantName").get()
    assert(moduleProjectTask != null)
    Task pluginProjectTask = pluginProject.tasks.named("assembleAar$variantName").get()
    assert(pluginProjectTask != null)
    moduleProjectTask.dependsOn(pluginProjectTask)

  2. added
    platform-androidAndroid applications specifically
    t: gradle"flutter build" and "flutter run" on Android
    a: buildBuilding flutter applications with the tool
    P1High-priority issues at the top of the work list
    on Apr 3, 2025
  3. gmackall commented on Apr 3, 2025

    @gmackall
    MemberAuthor

    More generally speaking, it is a common pattern that Gradle will let you get something (a task, an extension, etc)

    1. by name (string)
    2. by type

    We should probably generally speaking stop using (1). In Groovy we would sometimes get something by string, and then because Groovy is dynamic we would just call a method that we hoped would exist (without casting). In Kotlin we can't do that, and we probably shouldn't have been doing that anyways. We should just get it in a typesafe way so that we know the methods/fields, and then call them accordingly.

  4. reidbaker commented on Apr 8, 2025

    @reidbaker
    Member

    This will go to new a team member when they start next week and I know their github handle.

  5. added a commit that references this issue on Apr 8, 2025
  6. self-assigned this
    on Apr 21, 2025
  7. added a commit that references this issue on Aug 14, 2025
  8. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Aug 25, 2025
  9. flutter-triage-bot commented on Aug 25, 2025

    @flutter-triage-bot

    This issue is assigned to @mboetger but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  10. 99 remaining items

  11. added a commit that references this issue on Oct 8, 2026
  12. added a commit that references this issue on Oct 12, 2026
  13. added a commit that references this issue on Oct 20, 2026
  14. added 6 commits that reference this issue on Oct 29, 2026
  15. added a commit that references this issue on Oct 30, 2026
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 lista: buildBuilding flutter applications with the toolplatform-androidAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtriaged-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