Skip to content

[3.35.1] Android build fails when minSdk is set below 24 in build.gradle.kts #173823

Closed

Description

@khoadng

Steps to reproduce

  1. Create a new Flutter project with Flutter 3.35
  2. Navigate to android/app/build.gradle.kts
  3. Set minSdk to 21
  4. Build the Android app

Expected results

Build success

Actual results

Build fails with syntax error due to minSdk = 21 is replaced with minSdkVersion flutter.minSdkVersion

Code sample

Code sample
[Paste your code here]

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.35.1, on macOS 15.6 24G84 darwin-arm64, locale en-VN) [278ms]
    • Flutter version 3.35.1 on channel stable at /Users/khoa.nguyen/fvm/versions/3.35.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 20f8274939 (9 hours ago), 2025-08-14 10:53:09 -0700
    • Engine revision 1e9a811bf8
    • Dart version 3.9.0
    • DevTools version 2.48.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations,
      enable-lldb-debugging

[!] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [1,160ms]
    • Android SDK at /Users/khoa.nguyen/Library/Android/sdk
    • Emulator version 35.5.10.0 (build_id 13402964) (CL:N/A)
    • Platform android-36, build-tools 36.0.0
    • Java binary at: /opt/homebrew/opt/openjdk@17/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Homebrew (build 17.0.15+0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [668ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [8ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3) [7ms]
    • Android Studio at /Users/khoa.nguyen/Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)

[✓] VS Code (version 1.103.0) [6ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.116.0

[✓] Connected device (4 available) [5.9s]
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 16 (API 36) (emulator)
    • iPhone 16 Pro Max (mobile)  • 1FB5DCF2-7F04-4919-8C57-0E963C451C35 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-18-5 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 15.6 24G84 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 139.0.7258.67

[✓] Network resources [396ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. changed the title [-]Android build fails when minSdk is set below 24 in build.gradle.kts[/-] [+][3.35.1] Android build fails when minSdk is set below 24 in build.gradle.kts[/+] on Aug 15, 2025
  2. tirth-patel-nc commented on Aug 15, 2025

    @tirth-patel-nc
  3. added
    r: solvedIssue is closed as solved
    and removed
    in triagePresently being triaged by the triage team
    on Aug 15, 2025
  4. alex-medinsh commented on Aug 15, 2025

    @alex-medinsh
    Contributor

    Hi @tirth-patel-nc!

    I think there is a legitimate issue here. The report was about the migration script breaking your build.gradle.kts if it previously contained minSdk < 24, because it uses incorrect syntax when replacing the variable.

    It currently replaces

    minSdk = 21
    

    with

    minSdkVersion flutter.minSdkVersion
    

    which is not valid kts syntax.

  5. added
    in triagePresently being triaged by the triage team
    and removed
    r: solvedIssue is closed as solved
    on Aug 15, 2025
  6. tirth-patel-nc commented on Aug 15, 2025

    @tirth-patel-nc
    Member

    sorry for the oversight! @alex-medinsh appreciate the correction. I did notice this replacement in earlier triage but must have overlooked it in this case.

    Thanks for the report. Seeing the same behaviour with latest SDK versions. Doesn't happen on 3.32.8, hence marking it as a regression. Bisected it to #170882.

    Bisect Log
    tirthpatel@Tirths-MacBook-Pro flutter % flutter upgrade
    Building flutter tool...
    Resolving dependencies... (2.4s)
    Downloading packages... 
    Got dependencies.
    Flutter is already up to date on channel stable
    Flutter 3.35.1 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision 20f8274939 (17 hours ago) • 2025-08-14 10:53:09 -0700
    Engine • hash 6cd51c08a88e7bbe848a762c20ad3ecb8b063c0e (revision 1e9a811bf8) (35 hours ago) • 2025-08-13 23:35:25.000Z
    Tools • Dart 3.9.0 • DevTools 2.48.0
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad
    You need to start by "git bisect start"
    
    Do you want me to do it for you [Y/n]? Y
    status: waiting for both good and bad commits
    status: waiting for good commit(s), bad commit known
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good edada7c
    Bisecting: a merge base must be tested
    [e2dea95082e3a13d3084cacb6660d389449bab08] Fix warnings in FGP  (#166727)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good        
    Bisecting: 736 revisions left to test after this (roughly 10 steps)
    [c6fe412e9a06b634eb0d8942a04d9321a96103eb] Re-enable SelectableRegion web tests (#169541)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good 
    Bisecting: 368 revisions left to test after this (roughly 9 steps)
    [6983043d3bda5d3022d3e6fc9b2fef9860fc9d3d] Roll Packages from 7f41e758714a to 02770da46831 (5 revisions) (#171006)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good 
    Bisecting: 184 revisions left to test after this (roughly 8 steps)
    [750b87f551714d72a628ec8f4720d96de6f177bb] [ Widget Previews ] Add support for Pub Workspaces (#171538)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad  
    Bisecting: 91 revisions left to test after this (roughly 7 steps)
    [8b2f80e04f359bc12f7d257d026e80a490286a49] Run expression_evaluation_web_amd_test.dart on Mac/Windows (#171277)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good 
    Bisecting: 45 revisions left to test after this (roughly 6 steps)
    [b524df28bdf2658b3c68c8be6074d23b079d4863] Report feature flags enabled if the flutter tool crashes on a bot. (#171304)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good 
    Bisecting: 22 revisions left to test after this (roughly 5 steps)
    [4937e469d6d136ac66c08d221d07abd481b73a0c] [ Tool ] Update validator of NO_PROXY to explicitly match detected hosts (#171385)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect good 
    Bisecting: 11 revisions left to test after this (roughly 4 steps)
    [96d6ce0e65849a9cd814bbcdfb21d26436e52c25] Set width and height when creating <img> platform view for NetworkImage (#171474)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad  
    Bisecting: 5 revisions left to test after this (roughly 3 steps)
    [59ba3087e40d7896c919658c2b7653bfc3b47170] Deprecate: Mark AppBarTheme & AppBarThemeData color parameter as deprecated in favor of backgroundColor (#170624)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad
    Bisecting: 2 revisions left to test after this (roughly 1 step)
    [17848992dc09517fc8975b54d5d831802730665a] Roll Packages from 3dc682deffb4 to 205c50f07ec7 (3 revisions) (#171526)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad
    Bisecting: 0 revisions left to test after this (roughly 0 steps)
    [1dfb59d2811ce784bfa8a11231509bd835fdb4a7] Android min sdk 24 part 1 (#170882)
    tirthpatel@Tirths-MacBook-Pro flutter % git bisect bad
    1dfb59d2811ce784bfa8a11231509bd835fdb4a7 is the first bad commit
    commit 1dfb59d2811ce784bfa8a11231509bd835fdb4a7
    Author: Reid Baker <[email protected]>
    Date:   Wed Jul 2 14:30:22 2025 +0000
    
        Android min sdk 24 part 1 (#170882)
        
        - **bump template version, update migration code to handle api 21-23 and
        expand it to cover multiple min api level definitions**
        - **bump add to app project to minimum api level 24**
        - **PathUtilsTest converted to using config, removed test code that
        branched on versions older than 24**
        - **Update additional build.gradle files to have minsdk 24 and
        documenation**
        
        Related to #170807
        
        G3 cls
        - espresso https://critique.corp.google.com/cl/776592881
        - integration tests cl/778034198
        - removal of pre api 23 samples tests cl/777652802
        
        
        ## Pre-launch Checklist
        
        - [x] I read the [Contributor Guide] and followed the process outlined
        there for submitting PRs.
        - [x] I read the [Tree Hygiene] wiki page, which explains my
        responsibilities.
        - [x] I read and followed the [Flutter Style Guide], including [Features
        we expect every widget to implement].
        - [x] I signed the [CLA].
        - [x] I listed at least one issue that this PR fixes in the description
        above.
        - [x] I updated/added relevant documentation (doc comments with `///`).
        - [x] I added new tests to check the change I am making, or this PR is
        [test-exempt].
        - [x] I followed the [breaking change policy] and added [Data Driven
        Fixes] where supported.
        - [x] All existing and new tests are passing.
        
        ---------
        
        Co-authored-by: Gray Mackall <[email protected]>
    
     .../bin/tasks/gradle_desugar_classes_test.dart     |   9 +-
     dev/devicelab/lib/framework/apk_utils.dart         |  12 ---
     .../android/component1/build.gradle                |   2 +-
     .../app/build.gradle                               |   2 +-
     .../android_custom_host_app/SampleApp/build.gradle |   2 +-
     .../android_host_app_v2_embedding/app/build.gradle |   2 +-
     .../flutter/shell/platform/android/build.gradle    |   4 +-
     .../shell/platform/android/io/flutter/Build.java   |   2 +-
     .../io/flutter/view/AccessibilityBridge.java       |   3 +-
     .../embedding/android/FlutterActivityTest.java     |   3 +-
     .../flutter/embedding/android/FlutterViewTest.java |  30 +++---
     .../embedding/engine/loader/FlutterLoaderTest.java |  19 ----
     .../localization/LocalizationPluginTest.java       | 103 ---------------------
     .../platform/SingleViewPresentationTest.java       |   5 +-
     .../test/io/flutter/util/PathUtilsTest.java        |  16 +---
     .../io/flutter/view/AccessibilityBridgeTest.java   |  14 +--
     .../platform/android/test_runner/build.gradle      |   4 +-
     packages/flutter_tools/.gitignore                  |   3 +
     packages/flutter_tools/gradle/README.md            |  12 ++-
     .../src/main/kotlin/DependencyVersionChecker.kt    |   5 +-
     .../gradle/src/main/kotlin/FlutterExtension.kt     |   2 +-
     .../test/kotlin/DependencyVersionCheckerTest.kt    |  15 +--
     packages/flutter_tools/lib/src/android/README.md   |   8 +-
     .../lib/src/android/gradle_utils.dart              |   7 +-
     .../android/android_project_migration_test.dart    |  42 +++++++--
     .../test_data/deferred_components_config.dart      |   2 +-
     26 files changed, 118 insertions(+), 210 deletions(-)
    tirthpatel@Tirths-MacBook-Pro flutter % 
    stable : 3.35.1
    master : 3.33.0-1.0.pre-1430
    beta   : 3.36.0-0.1.pre 
    
    Build Logs
    Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
    Upgrading build.gradle.kts
    e: file:///Users/tirthpatel/test_app/android/app/build.gradle.kts:27:30: Expecting an element
    e: file:///Users/tirthpatel/test_app/android/app/build.gradle.kts:27:9: Function invocation 'minSdkVersion(...)' expected
    e: file:///Users/tirthpatel/test_app/android/app/build.gradle.kts:27:9: None of the following functions can be called with the arguments supplied:
    public abstract fun minSdkVersion(minSdkVersion: Int): Unit defined in com.android.build.api.dsl.ApplicationDefaultConfig
    public abstract fun minSdkVersion(minSdkVersion: String?): Unit defined in com.android.build.api.dsl.ApplicationDefaultConfig
    e: file:///Users/tirthpatel/test_app/android/app/build.gradle.kts:27:9: Variable expected
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/Users/tirthpatel/test_app/android/app/build.gradle.kts' line: 27
    
    * What went wrong:
    Script compilation errors:
    
      Line 27:         minSdkVersion flutter.minSdkVersion
                                            ^ Expecting an element
    
      Line 27:         minSdkVersion flutter.minSdkVersion
                       ^ Function invocation 'minSdkVersion(...)' expected
    
      Line 27:         minSdkVersion flutter.minSdkVersion
                       ^ None of the following functions can be called with the arguments supplied:
                           public abstract fun minSdkVersion(minSdkVersion: Int): Unit defined in com.android.build.api.dsl.ApplicationDefaultConfig
                           public abstract fun minSdkVersion(minSdkVersion: String?): Unit defined in com.android.build.api.dsl.ApplicationDefaultConfig
    
      Line 27:         minSdkVersion flutter.minSdkVersion
                       ^ Variable expected
    
    4 errors
    
    * Try:
    > Run with --stacktrace option to get the stack trace.
    > Run with --info or --debug option to get more log output.
    > Run with --scan to get full insights.
    > Get more help at https://help.gradle.org.
    
    BUILD FAILED in 1s
    Error: Gradle task assembleDebug failed with exit code 1
    
    Exited (1).
    Screen.Recording.2025-08-15.at.3.51.37.PM.mov
  7. 9 remaining items

  8. added
    r: fixedIssue is closed as already fixed in a newer version
    on Aug 20, 2025
  9. github-actions commented on Sep 3, 2025

    @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.

  10. locked as resolved and limited conversation to collaborators on Sep 3, 2025
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

    a: buildBuilding flutter applications with the toolc: regressionIt was better in the past than it is nowfound in release: 3.33Found to occur in 3.33found in release: 3.35Found to occur in 3.35fyi-toolFor the attention of Flutter Tool teamhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyr: fixedIssue is closed as already fixed in a newer versiont: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.workaround 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