Skip to content

[tool] Add initial non-plugin package support for Kotlin Gradle#11127

Merged
auto-submit[bot] merged 8 commits intoflutter:mainfrom
stuartmorgan-g:android-example-refresh-part-i-initial-non-plugin
Mar 3, 2026
Merged

[tool] Add initial non-plugin package support for Kotlin Gradle#11127
auto-submit[bot] merged 8 commits intoflutter:mainfrom
stuartmorgan-g:android-example-refresh-part-i-initial-non-plugin

Conversation

@stuartmorgan-g
Copy link
Collaborator

This adds support for non-plugin Gradle validation of packages that use Kotlin Gradle files rather than Groovy gradle files. More work will need to be done to be able to validate plugins that use Kotlin Gradle files, but this is enough for just Android apps.

As a test case for this new validation, this also migrates the animations example app to Kotlin Gradle. Rather than doing a manual migration, this was done by:

  • Deleting the entire example android/ directory
  • Recreating it on stable
  • Restoring android/.pluginToolsConfig.yaml (without changes)
  • Adding a Kotlin version of the Artifact Hub configuration
  • Removing the TODO comments that are part of the template Gradle files

Part of flutter/flutter#176065

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@stuartmorgan-g stuartmorgan-g added override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes labels Feb 26, 2026
@github-actions github-actions bot added p: animations platform-android triage-framework Should be looked at in framework triage labels Feb 26, 2026
@stuartmorgan-g
Copy link
Collaborator Author

version/chaneglog override: modernizing the example build files is not relevant to clients.

@stuartmorgan-g
Copy link
Collaborator Author

Assuming this looks good, I can do a follow-up PR to repeat this for all the other non-plugin examples (which are presumably all simple), and then we can tackle plugins one at a time (updating the tooling further when we do the first one).

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces initial support for validating non-plugin packages that use Kotlin Gradle files (.gradle.kts) in the gradle-check tool. This is achieved by updating the tool to recognize .kts files and apply specific validation logic for the Kotlin DSL. As a test case, the animations example's Android project is migrated from Groovy to Kotlin Gradle files. The changes include updating build logic, namespaces, and dependencies to conform to Kotlin DSL syntax and modern Gradle practices. The validation tool's tests are also expanded to cover these new Kotlin-based scenarios.

Comment on lines 103 to +121
// Returns the gradle file in the given directory.
File _getBuildGradleFile(Directory dir) => dir.childFile('build.gradle');
File _getBuildGradleFile(Directory dir) {
const buildGradleBaseName = 'build.gradle';
const buildGradleKtsBaseName = '$buildGradleBaseName.kts';
if (dir.childFile(buildGradleKtsBaseName).existsSync()) {
return dir.childFile(buildGradleKtsBaseName);
}
return dir.childFile(buildGradleBaseName);
}

// Returns the settings gradle file in the given directory.
File _getSettingsGradleFile(Directory dir) =>
dir.childFile('settings.gradle');
File _getSettingsGradleFile(Directory dir) {
const settingsGradleBaseName = 'settings.gradle';
const settingsGradleKtsBaseName = '$settingsGradleBaseName.kts';
if (dir.childFile(settingsGradleKtsBaseName).existsSync()) {
return dir.childFile(settingsGradleKtsBaseName);
}
return dir.childFile(settingsGradleBaseName);
}

Choose a reason for hiding this comment

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

medium

To reduce code duplication, the logic for finding a .gradle or .gradle.kts file could be extracted into a shared helper function.

  // Returns a Gradle file in the given directory, preferring .kts if it exists.
  File _getGradleFile(Directory dir, String baseName) {
    final File ktsFile = dir.childFile('$baseName.kts');
    if (ktsFile.existsSync()) {
      return ktsFile;
    }
    return dir.childFile(baseName);
  }

  // Returns the gradle file in the given directory.
  File _getBuildGradleFile(Directory dir) => _getGradleFile(dir, 'build.gradle');

  // Returns the settings gradle file in the given directory.
  File _getSettingsGradleFile(Directory dir) =>
      _getGradleFile(dir, 'settings.gradle');

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤷🏻

I didn't worry much about optimal structure in any of these changes since once we convert everything over we'll rip out all the non-Kotlin paths.

println("Using artifact hub")
maven {
url = uri(artifactRepoUrl)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This conversion from Groovy was done by Gemini. It recommended the get-and-null-check pattern rather than a direct conversion of the check-for-key-then-read Groovy code, because this is null safe rather than requiring a force unwrap. That seemed entirely reasonable to me.

The uri part I trusted it on 🤷🏻

@@ -1,2 +1,2 @@
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
org.gradle.jvmargs=-Xmx8G -XX:MaxMetaspaceSize=4G -XX:ReservedCodeCacheSize=512m -XX:+HeapDumpOnOutOfMemoryError
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I didn't see any reason not to just adopt the current template defaults here.

@stuartmorgan-g stuartmorgan-g requested a review from gmackall March 2, 2026 17:55
Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

LGTM

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 3, 2026
@auto-submit auto-submit bot merged commit 8212bdb into flutter:main Mar 3, 2026
81 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 4, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 4, 2026
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Mar 4, 2026
flutter/packages@9083bc9...82baf93

2026-03-04 [email protected] [camera_avfoundation] Fixes crash when
using ResolutionPreset.max with iPhone 17 (flutter/packages#11106)
2026-03-03 [email protected]
[camera_android_camerax] Allow usage of all use cases concurrently
(flutter/packages#10732)
2026-03-03 [email protected] [Many] Remove network policy from
metadata (flutter/packages#11165)
2026-03-03 [email protected] [Espresso] remove metadata network
policy (flutter/packages#11164)
2026-03-03 [email protected] [tool] Add initial non-plugin package
support for Kotlin Gradle (flutter/packages#11127)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request Mar 9, 2026
This is a follow-up to #11127, migrating the `android/` example apps of the non-plugin packages (since plugin example apps have more complexity) to current standards.

In each case this was done by
- Deleting the entire example `android/` directory
- Recreating it on `stable` (using `flutter.dev` as the `--org`, which is why some namespaces have changed)
- Adding a Kotlin version of the Artifact Hub configuration
- Removing the TODO comments that are part of the template Gradle files

This did result in some incidental changes to .gitignore and .metadata files, which I went ahead and included. (.metadata doesn't really handle incremental changes despite the structure, but it's also pretty much unused at the moment AFAIK). There are also a bunch of minor changes that align with the current template boilerplate, such as changes in xml explanatory comments, adjustments to build environment flags like memory allocated for the build process, etc. Since we don't have any reason we want to be different from the current template there, I included all of those changes.

This is the same pattern that was used in #11127

Part of flutter/flutter#176065

## Pre-Review Checklist

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
xxxOVALxxx pushed a commit to xxxOVALxxx/flutter that referenced this pull request Mar 10, 2026
…r#183240)

flutter/packages@9083bc9...82baf93

2026-03-04 [email protected] [camera_avfoundation] Fixes crash when
using ResolutionPreset.max with iPhone 17 (flutter/packages#11106)
2026-03-03 [email protected]
[camera_android_camerax] Allow usage of all use cases concurrently
(flutter/packages#10732)
2026-03-03 [email protected] [Many] Remove network policy from
metadata (flutter/packages#11165)
2026-03-03 [email protected] [Espresso] remove metadata network
policy (flutter/packages#11164)
2026-03-03 [email protected] [tool] Add initial non-plugin package
support for Kotlin Gradle (flutter/packages#11127)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit bot pushed a commit that referenced this pull request Mar 18, 2026
)

Following up from #11127, this is the initial example of converting a plugin build, rather than an example app build, to Kotlin gradle.

This conversion was done manually, but closely referencing the current plugin template files. It differs mostly in not having the parts that are specific to the use of Kotlin source files, since `local_auth` is still Java-only. Later (when we start adopting Kotlin Pigeon generation everywhere, for instance) some of the diffs relative to the template files will go away.

Unlike #11127 this did not require tool changes, as it turns out that the previous changes were enough to handle these files, but I did add more tests. As with #11127 I did not attempt to comprehensively duplicate all Groovy tests, since we should be able to relatively quickly convert everything in the repo, and then pull out the Groovy support and update all the tests to Kotlin.

Note that this does *not* convert the plugin's example app to Kotlin gradle, only the plugin itself. The example app for plugins are non-trivial enough (due to native tests) that they should be converted separately. This has the bonus effect of validating that the plugin migration didn't require any changes in the client app.

Part of flutter/flutter#176065

## Pre-Review Checklist

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App override: no changelog needed Override the check requiring CHANGELOG updates for most changes override: no versioning needed Override the check requiring version bumps for most changes p: animations platform-android triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants