Skip to content

Add our own wrapper for CommonExtension due to change in signature from 8.x->9.0 - #184433

Merged
auto-submit[bot] merged 9 commits into
flutter:masterfrom
gmackall:copy_agp_wrapper_branch
Apr 2, 2026
Merged

Add our own wrapper for CommonExtension due to change in signature from 8.x->9.0#184433
auto-submit[bot] merged 9 commits into
flutter:masterfrom
gmackall:copy_agp_wrapper_branch

Conversation

@gmackall

@gmackall gmackall commented Mar 31, 2026

Copy link
Copy Markdown
Member

@github-actions github-actions Bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Mar 31, 2026
@gmackall gmackall added the CICD Run CI/CD label Mar 31, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Mar 31, 2026
@gmackall gmackall added the CICD Run CI/CD label Mar 31, 2026
@github-actions github-actions Bot removed team-android Owned by Android platform team CICD Run CI/CD labels Mar 31, 2026
@gmackall gmackall added the CICD Run CI/CD label Mar 31, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@gmackall gmackall added the CICD Run CI/CD label Apr 1, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@gmackall gmackall added the CICD Run CI/CD label Apr 1, 2026
@gmackall gmackall changed the title Fix commonextension wrapper issue (todo improve title) Add our own wrapper for CommonExtension due to change in signature from 8.x->9.0 Apr 1, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@gmackall
gmackall marked this pull request as ready for review April 1, 2026 19:51
@gmackall
gmackall requested a review from a team as a code owner April 1, 2026 19:51
@gmackall gmackall added the CICD Run CI/CD label Apr 1, 2026

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

Copy link
Copy Markdown
Contributor

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 the AgpCommonExtensionWrapper class to address binary incompatibilities in the Android Gradle Plugin's CommonExtension between versions 8.x and 9.x. The wrapper delegates property and method access to specific Android extension types, such as ApplicationExtension and LibraryExtension, without directly importing CommonExtension. FlutterPluginUtils is updated to return this wrapper, and unit tests are adjusted to mock the necessary interfaces and build types. Feedback suggests that the ndkVersion property in the wrapper should be nullable to align with the Android Gradle Plugin DSL and prevent potential runtime errors.

}
}

var ndkVersion: String

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The ndkVersion property in the Android Gradle Plugin DSL is nullable. Declaring it as a non-nullable String in this wrapper could lead to a NullPointerException or a type mismatch at runtime if the property is not explicitly set in the build script.

Suggested change
var ndkVersion: String
var ndkVersion: String?

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 1, 2026
@gmackall gmackall added the CICD Run CI/CD label Apr 1, 2026
@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Apr 2, 2026
Merged via the queue into flutter:master with commit 249f25a Apr 2, 2026
152 of 153 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 2, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 3, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Apr 3, 2026
flutter/flutter@0f401ee...7245c3f

2026-04-03 [email protected] Roll Skia from c07c67045b6d to 5d847ba5c4aa (1 revision) (flutter/flutter#184570)
2026-04-03 [email protected] Roll Dart SDK from 3c7a79045b8b to 46f49142acd9 (1 revision) (flutter/flutter#184567)
2026-04-03 [email protected] Roll ICU from ee5f27adc28b to ff7995a708a1 (5 revisions) (flutter/flutter#184566)
2026-04-03 [email protected] Roll Skia from 9ae8231be181 to c07c67045b6d (4 revisions) (flutter/flutter#184562)
2026-04-03 [email protected] Roll Fuchsia Linux SDK from BFLjk6Uwd0gs_Hkdk... to PpL3Bn2YMb2h9LbdK... (flutter/flutter#184556)
2026-04-03 [email protected] Roll Skia from 0566b2f5f0d1 to 9ae8231be181 (1 revision) (flutter/flutter#184547)
2026-04-03 [email protected] Roll Dart SDK from 6008eaddd589 to 3c7a79045b8b (3 revisions) (flutter/flutter#184551)
2026-04-03 [email protected] Fix wide gamut macos integration test (flutter/flutter#184427)
2026-04-02 [email protected] forward an application name to DDS (flutter/flutter#184459)
2026-04-02 [email protected] Roll Skia from 973117cfa875 to 0566b2f5f0d1 (8 revisions) (flutter/flutter#184534)
2026-04-02 [email protected] Support different joins for stroked rects in uber_sdf, fix incorrect aa (flutter/flutter#184395)
2026-04-02 [email protected] [ Widget Preview ] Handle collections and records in custom preview annotations (flutter/flutter#184518)
2026-04-02 [email protected] Moves android_semantics_integration_test out of staging (flutter/flutter#184079)
2026-04-02 [email protected] Roll Packages from b3fcf14 to 66bf7ec (4 revisions) (flutter/flutter#184514)
2026-04-02 [email protected] Fix line breaks being lost when copying after selection gesture in SelectableRegion (flutter/flutter#184421)
2026-04-02 [email protected] Add plugin version to SwiftPM package symlink directory (flutter/flutter#183668)
2026-04-02 [email protected] Add our own wrapper for `CommonExtension` due to change in signature from 8.x->9.0 (flutter/flutter#184433)
2026-04-02 [email protected] [Android] Use EdgeToEdge.enable/WindowCompat for edge-to-edge mode instead of deprecated View flags (flutter/flutter#183072)
2026-04-02 [email protected] [data_assets] Cleanup tests (flutter/flutter#184209)
2026-04-02 [email protected] Enable SPM by default on Stable (flutter/flutter#184495)
2026-04-02 [email protected] Roll Dart SDK from d84bdfeb45eb to 6008eaddd589 (2 revisions) (flutter/flutter#184513)
2026-04-02 [email protected] Reland "Even more awaits" (flutter/flutter#184467)
2026-04-02 [email protected] Roll Skia from bb9fd8653739 to 973117cfa875 (2 revisions) (flutter/flutter#184498)
2026-04-02 [email protected] [ Widget Preview ] Use analysis server for widget preview detection (flutter/flutter#184473)
2026-04-02 [email protected] [web_ui] Fix avoid_type_to_string lint violation (flutter/flutter#184342)

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
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: 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
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
…r#11427)

flutter/flutter@0f401ee...7245c3f

2026-04-03 [email protected] Roll Skia from c07c67045b6d to 5d847ba5c4aa (1 revision) (flutter/flutter#184570)
2026-04-03 [email protected] Roll Dart SDK from 3c7a79045b8b to 46f49142acd9 (1 revision) (flutter/flutter#184567)
2026-04-03 [email protected] Roll ICU from ee5f27adc28b to ff7995a708a1 (5 revisions) (flutter/flutter#184566)
2026-04-03 [email protected] Roll Skia from 9ae8231be181 to c07c67045b6d (4 revisions) (flutter/flutter#184562)
2026-04-03 [email protected] Roll Fuchsia Linux SDK from BFLjk6Uwd0gs_Hkdk... to PpL3Bn2YMb2h9LbdK... (flutter/flutter#184556)
2026-04-03 [email protected] Roll Skia from 0566b2f5f0d1 to 9ae8231be181 (1 revision) (flutter/flutter#184547)
2026-04-03 [email protected] Roll Dart SDK from 6008eaddd589 to 3c7a79045b8b (3 revisions) (flutter/flutter#184551)
2026-04-03 [email protected] Fix wide gamut macos integration test (flutter/flutter#184427)
2026-04-02 [email protected] forward an application name to DDS (flutter/flutter#184459)
2026-04-02 [email protected] Roll Skia from 973117cfa875 to 0566b2f5f0d1 (8 revisions) (flutter/flutter#184534)
2026-04-02 [email protected] Support different joins for stroked rects in uber_sdf, fix incorrect aa (flutter/flutter#184395)
2026-04-02 [email protected] [ Widget Preview ] Handle collections and records in custom preview annotations (flutter/flutter#184518)
2026-04-02 [email protected] Moves android_semantics_integration_test out of staging (flutter/flutter#184079)
2026-04-02 [email protected] Roll Packages from b3fcf14 to 66bf7ec (4 revisions) (flutter/flutter#184514)
2026-04-02 [email protected] Fix line breaks being lost when copying after selection gesture in SelectableRegion (flutter/flutter#184421)
2026-04-02 [email protected] Add plugin version to SwiftPM package symlink directory (flutter/flutter#183668)
2026-04-02 [email protected] Add our own wrapper for `CommonExtension` due to change in signature from 8.x->9.0 (flutter/flutter#184433)
2026-04-02 [email protected] [Android] Use EdgeToEdge.enable/WindowCompat for edge-to-edge mode instead of deprecated View flags (flutter/flutter#183072)
2026-04-02 [email protected] [data_assets] Cleanup tests (flutter/flutter#184209)
2026-04-02 [email protected] Enable SPM by default on Stable (flutter/flutter#184495)
2026-04-02 [email protected] Roll Dart SDK from d84bdfeb45eb to 6008eaddd589 (2 revisions) (flutter/flutter#184513)
2026-04-02 [email protected] Reland "Even more awaits" (flutter/flutter#184467)
2026-04-02 [email protected] Roll Skia from bb9fd8653739 to 973117cfa875 (2 revisions) (flutter/flutter#184498)
2026-04-02 [email protected] [ Widget Preview ] Use analysis server for widget preview detection (flutter/flutter#184473)
2026-04-02 [email protected] [web_ui] Fix avoid_type_to_string lint violation (flutter/flutter#184342)

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
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: 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
nick-llewellyn added a commit to nick-llewellyn/nts that referenced this pull request Aug 21, 2026
* fix: support AGP 9 / Kotlin 2.2+ Android builds (NTS-161)

Closes #313. android/build.gradle.kts (the nts plugin's Android
module) used three APIs that AGP 9 and Kotlin 2.2+ raise to hard
script-compilation errors rather than warnings:

- `android { ... }` -- the classic extension-function accessor is
  deprecated once `android.newDsl=true`, the AGP 9 default.
- `kotlinOptions { jvmTarget = ... }` -- deprecation level raised to
  ERROR in Kotlin 2.2.0.
- `java.srcDirs("src/main/kotlin")` -- deprecated in favor of the
  `directories` mutable set.

Fix, mirroring the pattern other published Flutter plugins use for
the same migration (e.g. cunning_document_scanner):

- Apply `org.jetbrains.kotlin.android` only when the resolved AGP
  major version is below 9. AGP 9 ships built-in Kotlin support and
  is incompatible with the standalone plugin.
- Configure the Android extension via `configure<LibraryExtension>
  { ... }` instead of the `android { ... }` accessor.
- Move `jvmTarget` to `kotlin.compilerOptions`, guarded by
  `plugins.withId("org.jetbrains.kotlin.android")` so it only runs
  when that plugin is actually applied. AGP 9's built-in Kotlin
  defaults `jvmTarget` from `compileOptions.targetCompatibility`
  already, so no replacement is needed on that path.
- Add to `java.directories` instead of calling `srcDirs(...)`.

example/android/app/build.gradle.kts carries the identical pattern,
since the same Kotlin/AGP deprecations apply to any Flutter app
module, not just library modules. The example's own AGP pin moved
8.11.1 -> 9.2.1 and the Gradle wrapper 8.14 -> 9.7.1 so the fix is
exercised end to end by anyone building the example.

Verification:

- `flutter build apk --debug` against the example, unchanged
  (AGP 8.11.1, the previous pin): still builds clean, confirming no
  regression for hosts on AGP 8.x.
- `flutter build apk --debug` against the example on the new AGP
  9.2.1 / Gradle 9.7.1 pins: builds clean under Flutter's default
  compatibility shim (`android.newDsl=false` /
  `android.builtInKotlin=false`, which Flutter's own migrator injects
  today for any AGP 9 project).
- A minimal standalone Gradle project isolating just the `nts`
  plugin module's build.gradle.kts pattern, built against genuine AGP
  9.2.1 with `android.newDsl=true` and `android.builtInKotlin=true`
  forced on (bypassing Flutter's compatibility shim entirely):
  BUILD SUCCESSFUL, confirming the module script itself compiles
  and applies correctly under AGP 9's true new-DSL / built-in-Kotlin
  semantics, not just the shimmed default.
- Full end-to-end `newDsl=true` validation against the example app's
  `:app` module hits an unrelated, pre-existing Flutter Gradle Plugin
  limitation (flutter/flutter#184433 -- an `AbstractAppExtension`
  cast that AGP 9's true ApplicationExtension type doesn't satisfy).
  That is upstream of this package and outside its control; the
  isolated module-level test above is the relevant verification for
  this fix's actual scope.

CHANGELOG.md documents the fix under the accumulating `## 9.2`
header.

* fix: restore KGP classpath declaration, correct CHANGELOG claim

Addresses Copilot review feedback on PR #315:

- example/android/settings.gradle.kts: restore the
  org.jetbrains.kotlin.android "apply false" declaration. Flutter
  3.44's migrators (disable_built_in_kotlin_migration.dart,
  disable_new_dsl_migration.dart) currently force
  android.builtInKotlin=false and android.newDsl=false into
  gradle.properties even on AGP 9, so the example app and the nts
  plugin module both still need KGP resolvable on the classpath to
  satisfy their conditional pluginManager.apply(...) calls.
  "apply false" only adds the plugin to the classpath without
  applying it, so keeping it declared here is safe and does not
  reintroduce the AGP-9-built-in-Kotlin incompatibility.

- example/android/gradle.properties: commit the builtInKotlin=false
  / newDsl=false flags Flutter's migrator writes automatically on
  "flutter build"/"flutter run", per Flutter's own migration
  documentation and Gradle's best practice of committing
  gradle.properties.

- CHANGELOG.md: stop claiming example/android/build.gradle.kts
  "follows the same pattern" as the plugin module's migration -- that
  file only configures repositories/build directories and was not
  touched by this change. Only app/build.gradle.kts was migrated.

Verified with "flutter build apk --debug" and "--release" against
the restored KGP declaration.

* fix: gate KGP application on effective builtInKotlin, not just AGP major

Copilot correctly flagged that gating solely on the AGP major version
(agpMajor < 9) is wrong: AGP 9 still supports
android.builtInKotlin=false, which is exactly what Flutter 3.44's
migrators force into gradle.properties regardless of AGP version (see
example/android/gradle.properties). On that AGP-9-but-compat-mode
path, Flutter 3.38 (this package's floor) has no fallback that applies
KGP for us, so the plugin's Kotlin source set and the example app's
MainActivity.kt would silently fail to compile/apply.

Both gates (android/build.gradle.kts and
example/android/app/build.gradle.kts) now also read the effective
android.builtInKotlin Gradle property via
providers.gradleProperty(...), applying KGP whenever built-in Kotlin
is not actually in effect (AGP < 9, or AGP >= 9 with the property
explicitly set to false). Defaults to built-in-Kotlin-enabled when the
property is absent, matching AGP 9's own default.

Verified with flutter build apk --debug and --release against the
example app's current gradle.properties (android.builtInKotlin=false),
and confirmed the gate correctly skips applying KGP when
-Pandroid.builtInKotlin=true is forced.

* docs: call AGP 8.11.1 the previous pin, not the existing one

The example app's pin moved to 9.2.1 earlier in this same CHANGELOG
entry, so "existing pin" contradicted that statement. "Previous pin"
distinguishes the AGP 8.11.1 compatibility test from the checked-in
9.2.1 configuration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants