Skip to content

[flutter_plugin_android_lifecycle] Gradle Kotlin Script Error: Unresolved Reference compileSdkVersion #184133

Closed

Description

@vitormesquita-web

Steps to reproduce

  • Run flutter pub upgrade.
  • Try to build the Android project using flutter build apk
  • Where:
    Build file '/Users/--/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.3/android/build.gradle.kts' line: 28

  • What went wrong:
    Script compilation error:

    Line 28: compileSdk = flutter.compileSdkVersion
    ^ Unresolved reference: compileSdkVersion

1 error

Expected results

The Android project should compile successfully without errors.

Actual results

When attempting to build the Android project, the build process fails during the execution of the Kotlin Gradle script inside the flutter_plugin_android_lifecycle plugin. The build stops with the following error:

  • Where:
    Build file '/Users/ec2-user/.pub-cache/hosted/pub.dev/flutter_plugin_android_lifecycle-2.0.3/android/build.gradle.kts' line: 28

  • What went wrong:
    Script compilation error:

    Line 28: compileSdk = flutter.compileSdkVersion
    ^ Unresolved reference: compileSdkVersion

1 error

Code sample

Code sample

N/A

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
    Flutter (Channel stable, 3.38.4, on macOS 15.0 24A335 darwin-arm64, locale en-US) [648ms]
      • Flutter version 3.38.4 on channel stable at /Users/ec2-user/fvm/versions/3.38.4
      • Upstream repository https://github.com/flutter/flutter.git
      • Framework revision 66dd93f9a2 (4 months ago), 2025-12-03 14:56:10 -0800
      • Engine revision a5cb96369e
      • Dart version 3.10.3
      • DevTools version 2.51.1
      • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging

Activity

  1. vitormesquita-web commented on Mar 25, 2026

    @vitormesquita-web
    Author

    The same issue is also happening with other Android plugins after the update this morning:

    • flutter_plugin_android_lifecycle
    • google_maps_flutter_android
    • path_provider_android
    • video_player_android
    • webview_flutter_android

    All of them fail to build with the same Gradle Kotlin script error related to:
    Unresolved reference: compileSdkVersion

  2. mbcorona commented on Mar 26, 2026

    @mbcorona
    Member

    Hi @vitormesquita-web , thanks for the report. The latest plugin updates migrated to Kotlin DSL (build.gradle.kts) but appear to be missing the minimum Flutter SDK version constraints in their pubspec.yaml. This causes pub upgrade to incorrectly pull them on older SDKs like 3.38.4, breaking the build.

    I am routing this to the Android and Ecosystem teams to update the version constraints.

    Workaround: Until patched, either upgrade your Flutter SDK to the latest stable release.

  3. added
    team-androidOwned by Android platform team
    platform-androidAndroid applications specifically
    packageflutter/packages repository. See also p: labels.
    workaround availableThere is a workaround available to overcome the issue
    on Mar 26, 2026
  4. flutter-triage-bot commented on Mar 26, 2026

    @flutter-triage-bot

    Issue is assigned to multiple teams (ecosystem, android). Please ensure the issue has only one team-* label at a time. Use fyi-* labels to have another team look at the issue without reassigning it.

  5. BoboBirdFly commented on Mar 26, 2026

    @BoboBirdFly

    same problem, works for me if i overrides these: path_provider_foundation: 2.4.4
    flutter_plugin_android_lifecycle: 2.0.33
    path_provider_android: 2.2.22
    url_launcher_android: 6.3.28
    video_player_android: 2.9.4
    webview_flutter_android: 4.10.13

  6. 13 remaining items

  7. lemonliu2023 commented on Apr 29, 2026

    @lemonliu2023

    我的解决方案:
    改动在 moa-android/build.gradle (line 33):

    plugins {
    id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
    }
    原因:新版 Flutter Android 插件依赖 flutter.compileSdkVersion,但当前宿主工程是旧式 Flutter module 接入,Kotlin DSL 插件脚本在编译时拿不到 FlutterExtension 类型。把 Flutter Gradle plugin 放到宿主工程 classpath 上但不应用,可以让插件脚本正确解析这个 extension。

  8. j-ixcayau commented on May 11, 2026

    @j-ixcayau

    Still reproducing on Flutter 3.41.9 (stable) in an add-to-app setup (Flutter module embedded via include_flutter.groovy into a Kotlin Android host).

    Removing all our pinned Groovy plugin versions and running flutter pub upgrade pulls in camera_android_camerax 0.7.2 (the first KTS version). ./gradlew assembleDebug then fails with:

    e: …/camera_android_camerax-0.7.2/android/build.gradle.kts:40:26: Unresolved reference: compileSdkVersion

    FAILURE: Build failed with an exception.

    What went wrong: Script compilation error: Line 40: compileSdk = flutter.compileSdkVersion ^ Unresolved reference: compileSdkVersion

    The flutter extension that build.gradle.kts references isn't exposed when the plugin is consumed through include_flutter.groovy (add-to-app), only when consumed through the standalone Flutter Android Gradle plugin.

    Current workaround in our root pubspec.yaml — pinning every affected plugin to its last Groovy release:

    dependency_overrides:
      camera_android_camerax: 0.7.1
      file_selector_android: 0.5.2+4
      flutter_plugin_android_lifecycle: 2.0.33
      image_picker_android: 0.8.13+14
      path_provider_android: 2.2.22
      shared_preferences_android: 2.4.21
      url_launcher_android: 6.3.28
      webview_flutter_android: 4.10.11

    This works but blocks us from picking up newer fixes/features in any of those plugins. Would be great to see a path forward — either exposing flutter.compileSdkVersion to add-to-app Kotlin DSL, or making the plugins fall back to a sensible compile SDK when the extension isn't available.

  9. github-actions commented on May 12, 2026

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.

    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.

    Thanks for your contribution.

  10. github-actions commented on May 26, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on May 26, 2026
  12. jesswrd commented on Jun 23, 2026

    @jesswrd
    Contributor

    Looks like someone else was able to repro and has a workaround: #188339. Let me see if I can repro this.

  13. unlocked this conversation on Jul 21, 2026
  14. github-actions commented on Jul 21, 2026

    @github-actions

    Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now.

    If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones.

    Thanks for your contribution.

  15. G0retZ commented on Jul 28, 2026

    @G0retZ

    I experience the same issue in my add-to-app flutter scenario.

    e: file:///home/admin/.pub-cache/hosted/pub.dev/in_app_purchase_android-0.5.0/android/build.gradle.kts:44:26: Unresolved reference: compileSdkVersion
    Namespace Missing: :in_app_purchase_android
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/home/admin/.pub-cache/hosted/pub.dev/in_app_purchase_android-0.5.0/android/build.gradle.kts' line: 44
    
    * What went wrong:
    Script compilation error:
    
      Line 44:     compileSdk = flutter.compileSdkVersion
                                        ^ Unresolved reference: compileSdkVersion
    
    1 error
    
    

    Looks like the issue is a difference in how KTS and Groovy script work. AI summary:

    Why that suffices for Groovy but not Kotlin DSL
    
    - Groovy (0.4.0+8) — dynamically resolved. flutter is looked up on the project's dynamic object when the android { } block executes. By then the extension exists → resolves → compileSdk = 36. ✅
    - Kotlin DSL (0.5.x) — statically compiled before any of it executes. Kotlin DSL only generates typed accessors for extensions contributed by plugins applied in that script's own plugins { } block. An extension created imperatively by a different project's plugin is invisible to the script compiler, so it fails at script compilation: Unresolved reference: compileSdkVersion. ✅→❌
    
    That also explains the follow-on Namespace Missing: :in_app_purchase_android — the script never compiled, so its android { namespace = … } block never ran.
    
    So the regression is upstream's Groovy → Kotlin DSL migration of the plugin's build file (0.4.x → 0.5.x), which turned a working dynamic lookup into a compile-time failure under add-to-app. In a normal Flutter app build it works either way, because there the app's settings.gradle applies dev.flutter.flutter-plugin-loader and the plugin ends up on the script's own classpath. Add-to-app's module_plugin_loader.gradle never does that — which is why this repo specifically is affected.
    
    Two useful corollaries:
    - Upgrading Flutter only helps if a newer module_plugin_loader/PluginHandler makes the extension statically visible (e.g. by actually applying the plugin to plugin projects rather than just create-ing the extension). Worth checking against a 3.44+ SDK before treating the upgrade as the fix.
    - Any other plugin that migrates its Android build file to .kts + flutter.compileSdkVersion will break this repo the same way — so the patch-script approach may need to generalize.
    

    Hope this will help with the issue investigation.

  16. github-actions commented on Aug 11, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  17. locked as resolved and limited conversation to collaborators on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority issues at the top of the work listpackageflutter/packages repository. See also p: labels.platform-androidAndroid applications specificallyteam-androidOwned by Android platform teamtriaged-androidTriaged by Android platform teamwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsworkaround availableThere is a workaround available to overcome the issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions