Skip to content

Repeated release builds that use Android flavors and flutter_localizations fail with gradle error #163591

@s9th

Description

@s9th

Steps to reproduce

  1. Create new Flutter project (I used latest Flutter 3.29)
  2. Add flavors to /android/app/build.gradle.kts
   flavorDimensions += "flavor-type" 
    productFlavors {
        create("dev") {
            dimension = "flavor-type"
            applicationId = "com.Li3NK.spark.dev"
            resValue("string", "app_name", "Spark dev")
        }
        create("prod") {
            dimension = "flavor-type"
            applicationId = "com.Li3NK.spark"
            resValue("string", "app_name", "Spark")
        }
    }
  1. Add l10n.yaml file to the root of the project
    arb-dir: lib/l10n template-arb-file: app_en.arb output-localization-file: app_localizations.dart synthetic-package: false
  2. Add /lib/l10n/app_en.arb file
{
  "commonYes": "Yes"
}
  1. Generate the localization files with flutter gen-l10n if they are not generated automatically
  2. Modify main.dart to use the localized string
import 'package:flutter/material.dart';
import 'package:bug/l10n/app_localizations.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(body: Center(child: Text(AppLocalizations.of(context)!.commonYes))),
    );
  }
}
  1. Run flutter build apk --release --flavor=dev once. It should pass succesfully
  2. Run the same command again

Expected results

Second build is also successful

Actual results

Second build fails with gradle exception (see logs below). This can be circumvented by always running flutter clean and flutter pub get, but it's not the best solution for large projects with a long build time

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:bug/l10n/app_localizations.dart';

void main() {
  runApp(const MainApp());
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(body: Center(child: Text(AppLocalizations.of(context)!.commonYes))),
    );
  }
}

Screenshots or Video

No response

Logs

Logs
`
Running Gradle task 'assembleDevRelease'...                          
FAILURE: Build failed with an exception.

* What went wrong:
Some problems were found with the configuration of task ':app:compileFlutterBuildProdRelease' (type 'FlutterTask').
  - Gradle detected a problem with the following location: 'D:\Misc\Code\test_329_create\lib\l10n\app_localizations_en.dart'.

    Reason: Task ':app:compileFlutterBuildDevRelease' uses this output of task ':app:compileFlutterBuildProdRelease' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.       

    Possible solutions:
      1. Declare task ':app:compileFlutterBuildProdRelease' as an input of ':app:compileFlutterBuildDevRelease'.
      2. Declare an explicit dependency on ':app:compileFlutterBuildProdRelease' from ':app:compileFlutterBuildDevRelease' using Task#dependsOn.
      3. Declare an explicit dependency on ':app:compileFlutterBuildProdRelease' from ':app:compileFlutterBuildDevRelease' using Task#mustRunAfter.
`

Flutter Doctor output

Doctor output
└ $ flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version
    10.0.26100.3194], locale uk-UA)
[√] Windows Version (11 Pro 64-bit, 24H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK
    version 35.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community
    2022 17.12.3)
[√] Android Studio (version 2024.2)
[√] VS Code (version 1.97.2)
[√] Connected device (3 available)
[√] Network resources

• No issues found!
                                                      pwsh | 10:36:10
┌ S9Th@S9Th-PC  test_329_create 
└ $ flutter doctor -v 
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version
    10.0.26100.3194], locale uk-UA) [367ms]
    • Flutter version 3.29.0 on channel stable at
      D:\Misc\Code\env\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 35c388afb5 (9 days ago), 2025-02-10 12:48:41
      -0800
    • Engine revision f73bfc4522
    • Dart version 3.7.0
    • DevTools version 2.42.2

[√] Windows Version (11 Pro 64-bit, 24H2, 2009) [4,6s]

[√] Android toolchain - develop for Android devices (Android SDK
    version 35.0.0) [1 850ms]
    • Android SDK at D:\Misc\Code\env\AndroidSDK
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = D:\Misc\Code\env\AndroidSDK
    • Java binary at: C:\Program Files\Android\Android
      Studio\jbr\bin\java
      This is the JDK bundled with the latest Android Studio
      installation on this machine.
      To manually set the JDK path, use: `flutter config
      --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build
      21.0.4+-12508038-b607.1)
    • All Android licenses accepted.

[√] Chrome - develop for the web [84ms]
    • Chrome at C:\Program Files
      (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community
    2022 17.12.3) [83ms]
    • Visual Studio at C:\Program Files\Microsoft Visual
      Studio\2022\Community
    • Visual Studio Community 2022 version 17.12.35527.113
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2024.2) [21ms]
    • Android Studio at C:\Program Files\Android\Android Studio      
    • 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.4+-12508038-b607.1)

[√] VS Code (version 1.97.2) [19ms]
    • VS Code at C:\Users\S9Th\AppData\Local\Programs\Microsoft VS
      Code
    • Flutter extension version 3.104.0

[√] Connected device (3 available) [224ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft       
      Windows [Version 10.0.26100.3194]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome   
      132.0.6834.197
    • Edge (web)        • edge    • web-javascript • Microsoft Edge  
      133.0.3065.69

[√] Network resources [342ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Labels

P1High-priority issues at the top of the work lista: internationalizationSupporting other languages or locales. (aka i18n)c: regressionIt was better in the past than it is nowfound in release: 3.29Found to occur in 3.29found in release: 3.32Found to occur in 3.32found in release: 3.33Found to occur in 3.33fyi-toolFor the attention of Flutter Tool teamplatform-androidAndroid applications specificallyplatform-windowsBuilding on or for Windows specificallyteam-androidOwned by Android platform team

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions