Repository navigation
Description
Filed as a separate issue at @jesswrd's request from #181557 (comment).
Steps to reproduce
- Android host app on AGP 9.2.1 / Gradle 9.6.1 (Kotlin DSL build scripts).
- Flutter module included from source via
include_flutter.groovy(add-to-app). - AGP 9 defaults left as is (
android.newDsl/android.builtInKotlinnot overridden in the host'sgradle.properties). - Run Gradle sync (or any configuration).
Flutter 3.47.1 stable / Dart 3.13.1. All plugin dependencies already migrated off unconditional KGP.
Expected results
Configuration succeeds, or fails with a clear actionable message.
Actual results
Applying dev.flutter.flutter-gradle-plugin to the module project fails:
Caused by: java.lang.NullPointerException
at com.flutter.gradle.FlutterPluginUtils.getLegacyAndroidExtension$gradle(FlutterPluginUtils.kt:514)
at com.flutter.gradle.plugins.PluginHandler$Companion.configurePluginDependencies(PluginHandler.kt:218)
at com.flutter.gradle.plugins.PluginHandler.configurePlugins$gradle(PluginHandler.kt:69)
at com.flutter.gradle.FlutterPlugin.addFlutterTasks(FlutterPlugin.kt:505)
at com.flutter.gradle.FlutterPlugin.apply(FlutterPlugin.kt:136)
Analysis
With newDsl=true (the AGP 9 default) the legacy BaseExtension is not registered, so getLegacyAndroidExtension's project.extensions.findByType(BaseExtension::class.java)!! throws. getLegacyAndroidExtension has ~14 call sites in 3.47.1 (PluginHandler.kt, FlutterPlugin.kt:249, FlutterPluginUtils.kt:533/797/923), so subsequent failures are likely once the first path is fixed — #191218 appears to cover this first one (buildModeFor / plugin dependency wiring).
Workaround
Per the migration docs: set android.newDsl=false and android.builtInKotlin=false in the host app's gradle.properties. Works, confirmed.
Related
#180137 (newDsl migration umbrella), #181557 (AGP 9 umbrella).
Happy to test snapshots against our host app once the add-to-app path is wired through the new DSL.
Activity
mbcorona commentedon Aug 25, 2026
Thanks for the report and stack trace. Confirmed cause: getLegacyAndroidExtension does findByType(BaseExtension)!!, which NPEs under AGP 9's newDsl default since the legacy BaseExtension isn't registered. Routing to the Android team for further investigation.
mboetger commentedon Aug 25, 2026
To @jesswrd to investigate a better error messaging
Migrate Android build to Gradle 9 / AGP 9.4.0
Silence obsolete-Java-8-target and native-access build warnings
[AGP 9.1.0 Migration flutter#8] Unify add-to-app module wiring on the…
Daracul commentedon Oct 19, 2026
Confirming the fix from #192116 on a production add-to-app setup.
Setup
include_flutter.groovyandroid.newDslnot overridden,android.builtInKotlin=true), noorg.jetbrains.kotlin.androidapplied anywhere in the hostResult
:app:assembleDebugbuilds, the app runs and Flutter screens work on a device. ThegetLegacyAndroidExtensionNPE from this report is gone, so from our side this issue can be closed once the fix reaches stable.Two add-to-app gaps we hit on the way (not this bug, reporting for completeness; happy to file them separately if preferred):
Kotlin-DSL build scripts of plugins fail with
Unresolved reference 'compileSdkVersion'oncompileSdk = flutter.compileSdkVersion(e.g. shared_preferences_android 2.4.28,build.gradle.kts:42). In add-to-app theflutterextension type is not on the host root buildscript classpath, so the Kotlin DSL cannot generate the accessor. The workaround from [add2app] [flutter_plugin_android_lifecycle] Gradle Kotlin Script Error: Unresolved Reference compileSdkVersion #188339 (declaredev.flutter.flutter-gradle-pluginwithapply falsein the host rootplugins {}) works, but only when the included build is present, i.e. only in the from-source configuration. [add2app] [flutter_plugin_android_lifecycle] Gradle Kotlin Script Error: Unresolved Reference compileSdkVersion #188339 was closed as a duplicate of [flutter_plugin_android_lifecycle] Gradle Kotlin Script Error: Unresolved Reference compileSdkVersion #184133, which was then closed for lack of info, so the gap currently has no open tracking issue.:flutter:compileFlutterBuildDebug(FlutterTask) callsTask.projectat execution time, which Gradle 9.6 reports as a configuration cache problem (8 problems, 1 unique). Not fatal in warning mode.[AGP 9.1.0 Migration flutter#8] Unify add-to-app module wiring on the…