Skip to content

[Android] Flutter 3.35.1 cannot customize the version code during compilation. #173917

Closed

Description

@mumu-lhl

Steps to reproduce

Add this code to build.gradle.kts:

val abiCodes = mapOf("x86_64" to 1, "armeabi-v7a" to 2, "arm64-v8a" to 3, "universal" to 4)

androidComponents {
    onVariants { variant ->

        variant.outputs.forEach { output ->
            val name = output.filters.find { it.filterType == ABI }?.identifier

            val baseAbiCode = abiCodes[name ?: "universal"]
            if (baseAbiCode != null) {
                output.versionCode.set(output.versionCode.get() * 10000 + baseAbiCode * 1000)
            }
        }
    }
}

It works fine in Flutter 3.32.X, but not in 3.35.X. This issue is suspected to be caused by #169816.

Expected results

Version code for each arch:

  • x86_64 - XX1000
  • armeabi-v7a - XX2000
  • arm64-v8a - XX3000
  • universal - XX4000

Since the format XX[version code] is required by F-Droid, I hope there is a solution that can achieve this.

Actual results

Version code for each arch:

  • x86_64 - 40xx
  • armeabi-v7a - 10XX
  • arm64-v8a - 20XX

Code sample

Same as above.

Screenshots or Video

Logs

Flutter Doctor output

It doesn't matter.

Activity

  1. tirth-patel-nc commented on Aug 18, 2025

    @tirth-patel-nc
    Member

    @mumu-lhl thanks for the report. I added the snippet in build.gradle.kts (both project and app level) but ran into errors for both 3.32 & 3.35. Could you please share a proper runnable snippet and any missing steps/config so we can verify on our end? Since you confirmed it’s a regression, we’d like to reproduce it correctly.

    tirthpatel@Tirths-MacBook-Pro au18 % flutter build apk --split-per-abi 
    e: file:///Users/tirthpatel/au18/android/app/build.gradle.kts:52:63: Unresolved reference: ABI
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/Users/tirthpatel/au18/android/app/build.gradle.kts' line: 52
    
    * What went wrong:
    Script compilation error:
    
      Line 52:             val name = output.filters.find { it.filterType == ABI }?.identifier
                                                                             ^ Unresolved reference: ABI
    
    1 error
    
    * 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
    Running Gradle task 'assembleRelease'...                         1,640ms
    Gradle task assembleRelease failed with exit code 1
    tirthpatel@Tirths-MacBook-Pro au18 % 

    also please confirm whether #62005 is somewhat related to your case or not.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 18, 2025
  3. mumu-lhl commented on Aug 18, 2025

    @mumu-lhl
    Author
  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Aug 18, 2025
  5. changed the title [-][Android] Flutter 3.35.1 cannot customize the version code during compilation.[/-] [+][android] flutter 3.35.1 cannot customize version code due to syntax error caused by gradle migration script[/+] on Aug 19, 2025
  6. changed the title [-][android] flutter 3.35.1 cannot customize version code due to syntax error caused by gradle migration script[/-] [+][Android] Flutter 3.35.1 cannot customize the version code during compilation.[/+] on Aug 19, 2025
  7. tirth-patel-nc commented on Aug 19, 2025

    @tirth-patel-nc
    Member

    @mumu-lhl thanks for the file. The missing part was adding the import, using the correct build command, (flutter build apk --split-per-abi) and verifying with aapt dump badging. Please include such crucial details in reports.

    Thanks for the report. Seeing the same behaviour with latest SDK versions.

    stable : 3.35.1
    master : 3.33.0-1.0.pre-1468
    beta   : 3.36.0-0.1.pre
    
    build.gradle.kts
    import com.android.build.api.variant.FilterConfiguration.FilterType.*
    
    plugins {
        id("com.android.application")
        id("kotlin-android")
        // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
        id("dev.flutter.flutter-gradle-plugin")
    }
    
    android {
        namespace = "com.example.au19"
        compileSdk = flutter.compileSdkVersion
        ndkVersion = flutter.ndkVersion
    
        compileOptions {
            sourceCompatibility = JavaVersion.VERSION_11
            targetCompatibility = JavaVersion.VERSION_11
        }
    
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_11.toString()
        }
    
        defaultConfig {
            // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
            applicationId = "com.example.au19"
            // You can update the following values to match your application needs.
            // For more information, see: https://flutter.dev/to/review-gradle-config.
            minSdk = flutter.minSdkVersion
            targetSdk = flutter.targetSdkVersion
            versionCode = flutter.versionCode
            versionName = flutter.versionName
        }
    
        buildTypes {
            release {
                // TODO: Add your own signing config for the release build.
                // Signing with the debug keys for now, so `flutter run --release` works.
                signingConfig = signingConfigs.getByName("debug")
            }
        }
    }
    
    flutter {
        source = "../.."
    }
    
    val abiCodes = mapOf("x86_64" to 1, "armeabi-v7a" to 2, "arm64-v8a" to 3, "universal" to 4)
    
    androidComponents {
        onVariants { variant ->
    
            variant.outputs.forEach { output ->
                val name = output.filters.find { it.filterType == ABI }?.identifier
    
                val baseAbiCode = abiCodes[name ?: "universal"]
                if (baseAbiCode != null) {
                    output.versionCode.set(output.versionCode.get() * 10000 + baseAbiCode * 1000)
                }
            }
        }
    }

    Output: 3.32.8

    tirthpatel@Tirths-MacBook-Pro au19 % ~/Library/Android/sdk/build-tools/36.0.0/aapt dump badging ~/au19/build/app/outputs/flutter-apk/app-x86_64-release.apk | grep versionCode
    package: name='com.example.au19' versionCode='11000' versionName='1.0.0' platformBuildVersionName='15' platformBuildVersionCode='35' compileSdkVersion='35' compileSdkVersionCodename='15'
    tirthpatel@Tirths-MacBook-Pro au19 % ~/Library/Android/sdk/build-tools/36.0.0/aapt dump badging ~/au19/build/app/outputs/flutter-apk/app-arm64-v8a-release.apk | grep versionCode
    package: name='com.example.au19' versionCode='13000' versionName='1.0.0' platformBuildVersionName='15' platformBuildVersionCode='35' compileSdkVersion='35' compileSdkVersionCodename='15'
    tirthpatel@Tirths-MacBook-Pro au19 % ~/Library/Android/sdk/build-tools/36.0.0/aapt dump badging ~/au19/build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk | grep versionCode
    package: name='com.example.au19' versionCode='12000' versionName='1.0.0' platformBuildVersionName='15' platformBuildVersionCode='35' compileSdkVersion='35' compileSdkVersionCodename='15'

    Output: 3.35.1, 3.33.0-1.0.pre-1468, 3.36.0-0.1.pre

    tirthpatel@Tirths-MacBook-Pro au19 % ~/Library/Android/sdk/build-tools/36.0.0/aapt dump badging ~/au19/build/app/outputs/flutter-apk/app-x86_64-release.apk | grep versionCode   
    package: name='com.example.au19' versionCode='4001' versionName='1.0.0' platformBuildVersionName='16' platformBuildVersionCode='36' compileSdkVersion='36' compileSdkVersionCodename='16'
    tirthpatel@Tirths-MacBook-Pro au19 % ~/Library/Android/sdk/build-tools/36.0.0/aapt dump badging ~/au19/build/app/outputs/flutter-apk/app-arm64-v8a-release.apk | grep versionCode  
    package: name='com.example.au19' versionCode='2001' versionName='1.0.0' platformBuildVersionName='16' platformBuildVersionCode='36' compileSdkVersion='36' compileSdkVersionCodename='16'
    tirthpatel@Tirths-MacBook-Pro au19 % ~/Library/Android/sdk/build-tools/36.0.0/aapt dump badging ~/au19/build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk | grep versionCode
    package: name='com.example.au19' versionCode='1001' versionName='1.0.0' platformBuildVersionName='16' platformBuildVersionCode='36' compileSdkVersion='36' compileSdkVersionCodename='16'
  8. added
    c: regressionIt was better in the past than it is now
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    platform-androidAndroid applications specifically
    team-androidOwned by Android platform team
    toolAffects the "flutter" command-line tool. See also t: labels.
    fyi-toolFor the attention of Flutter Tool team
    and removed
    in triagePresently being triaged by the triage team
    on Aug 19, 2025
  9. 37 remaining items

  10. mboetger commented on Sep 8, 2025

    @mboetger
    Contributor

    @gmackall - this was re-opened. Can you take a look?

  11. gmackall commented on Sep 8, 2025

    @gmackall
    Member

    From https://github.com/flutter/flutter/blame/3.35.3/packages/flutter_tools/gradle/src/main/kotlin/FlutterPlugin.kt#L637-L640:

    output.versionCodeOverride = abiVersionCode * 1000 + (
    versionCodeIfPresent
    ?: variant.mergedFlavor.versionCode as Int
    )
    versionCodeIfPresent was added in Flutter 3.35.3 to "fix" this issue. In order to fix this issue without introducing a breaking-change, the fix should have been to use versionCodeIfPresent w/o modifying it like:

    output.versionCodeOverride = versionCodeIfPresent ?: abiVersionCode * 1000 + (variant.mergedFlavor.versionCode as Int)

    Running @adil192 s code snippet on 3.29.3 and on master I see the same outputs:

    mackall-macbookpro:versioncoderoundtwo mackall$ /Users/mackall/Library/Android/sdk/cmdline-tools/latest/bin/apkanalyzer manifest version-code build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk && /Users/mackall/Library/Android/sdk/cmdline-tools/latest/bin/apkanalyzer manifest version-code build/app/outputs/flutter-apk/app-arm64-v8a-release.apk && /Users/mackall/Library/Android/sdk/cmdline-tools/latest/bin/apkanalyzer manifest version-code build/app/outputs/flutter-apk/app-x86_64-release.apk
    1011
    2011
    4011
    

    Indicating this is not a breaking change (though it is different from the broken behavior on 3.32, see #169790). I also see the same outputs on this version for the snippet being used to modify version codes here

    Is this different from what you see? (any of @ImranR98 , @rusty-snake , or @adil192 feel free to reply!) If so can you confirm this is not a breaking change but instead a return to #49544? If so feel free to follow up on that issue, and if not let me know what I'm missing

  12. adil192 commented on Sep 9, 2025

    @adil192
    Contributor

    @gmackall Thanks for investigating. I see the same with a minimal example. I looked some more into it and it seems unrelated to Flutter 3.35, but rather in my switch from groovy to kotlin gradle files.

    The solution was just to switch back to the older android.applicationVariants api. I tried it before but it didn't work for some reason, but it's working now...

    val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86_64" to 3)
    android.applicationVariants.configureEach {
        val variant = this
        variant.outputs.forEach { output ->
            val abiVersionCode = abiCodes[output.filters.find { it.filterType == "ABI" }?.identifier]
            if (abiVersionCode != null) {
                (output as ApkVariantOutputImpl).versionCodeOverride = variant.versionCode * 10 + abiVersionCode
            }
        }
    }
  13. gmackall commented on Sep 10, 2025

    @gmackall
    Member

    @adil192 Glad to hear you see the same.

    I'm going to close this again for now based on that. @ImranR98 and @rusty-snake feel free to follow up if you still feel this behavior is broken in comparison to how it functioned on 3.29.

  14. added a commit that references this issue on Sep 13, 2025
  15. github-actions commented on Sep 25, 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.

  16. locked as resolved and limited conversation to collaborators on Sep 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P0Critical issues such as a build break or regressionc: regressionIt was better in the past than it is nowcp: betacherry pick this pull request to beta release candidate branchcp: stablecherry pick this pull request to stable release candidate branchfound 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.triaged-androidTriaged by Android platform team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions